diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/WhitelistInvitesCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/WhitelistInvitesCmd.java index 91af04e..bfea150 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/WhitelistInvitesCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/WhitelistInvitesCmd.java @@ -24,8 +24,7 @@ import java.util.stream.Collectors; /** - * - * @author John Grosh (john.a.grosh@gmail.com) + * @author Michael Ritter (Kantenkugel) */ public class WhitelistInvitesCmd extends Command { diff --git a/src/main/java/com/jagrosh/vortex/pro/ProFeature.java b/src/main/java/com/jagrosh/vortex/pro/ProFeature.java index 1b349b4..6c2199e 100644 --- a/src/main/java/com/jagrosh/vortex/pro/ProFeature.java +++ b/src/main/java/com/jagrosh/vortex/pro/ProFeature.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 John Grosh (john.a.grosh@gmail.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jagrosh.vortex.pro; import java.lang.annotation.ElementType; @@ -5,6 +20,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * @author Michael Ritter (Kantenkugel) + */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface ProFeature diff --git a/src/main/java/com/jagrosh/vortex/pro/VortexPro.java b/src/main/java/com/jagrosh/vortex/pro/VortexPro.java index bd615d0..f5fea7d 100644 --- a/src/main/java/com/jagrosh/vortex/pro/VortexPro.java +++ b/src/main/java/com/jagrosh/vortex/pro/VortexPro.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 John Grosh (john.a.grosh@gmail.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jagrosh.vortex.pro; import java.lang.reflect.Constructor; @@ -8,6 +23,9 @@ import java.util.Set; import java.util.stream.Collectors; +/** + * @author Michael Ritter (Kantenkugel) + */ public class VortexPro { private static final Map, Object> IMPLS = new HashMap<>(); @@ -31,16 +49,13 @@ implClass = (Class) tmpClass; } catch(ClassNotFoundException ignored) {} - if(implClass == null) + if(implClass == null && anno.mock() != Object.class) { - if(anno.mock() != Object.class) + if(!apiClass.isAssignableFrom(anno.mock()) || anno.mock().isInterface()) { - if(!apiClass.isAssignableFrom(anno.mock()) || anno.mock().isInterface()) - { - throw new IllegalStateException("Class " + anno.mock().getName() + " can't be converted to a instance of " + apiClass.getName()); - } - implClass = (Class) anno.mock(); + throw new IllegalStateException("Class " + anno.mock().getName() + " can't be converted to a instance of " + apiClass.getName()); } + implClass = (Class) anno.mock(); } try { @@ -48,14 +63,18 @@ if(implClass != null) { Set> constructors = Arrays.stream(implClass.getConstructors()) - .filter(c -> c.getParameterCount() == args.length) + .filter(c -> c.getParameterCount() == 0 || c.getParameterCount() == args.length) .map(c -> (Constructor) c) .collect(Collectors.toSet()); if(constructors.size() != 1) { - throw new IllegalArgumentException("Could not find a Constructor with matching amount of arguments. Arguments provided: " + Arrays.toString(args)); + throw new IllegalArgumentException("Could not find a (single) Constructor with 0 or matching amount of arguments. Arguments provided: " + Arrays.toString(args)); } - instance = constructors.iterator().next().newInstance(args); + Constructor constructor = constructors.iterator().next(); + if(constructor.getParameterCount() == 0) + instance = constructor.newInstance(); + else + instance = constructor.newInstance(args); } IMPLS.put(apiClass, instance); return instance; diff --git a/src/main/java/com/jagrosh/vortex/pro/api/AvatarUtil.java b/src/main/java/com/jagrosh/vortex/pro/api/AvatarUtil.java index 384e011..340fb33 100644 --- a/src/main/java/com/jagrosh/vortex/pro/api/AvatarUtil.java +++ b/src/main/java/com/jagrosh/vortex/pro/api/AvatarUtil.java @@ -1,8 +1,26 @@ +/* + * Copyright 2018 John Grosh (john.a.grosh@gmail.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jagrosh.vortex.pro.api; import com.jagrosh.vortex.pro.ProFeature; import net.dv8tion.jda.core.entities.User; +/** + * @author Michael Ritter (Kantenkugel) + */ @ProFeature("com.jagrosh.vortex.pro.AvatarUtil") public interface AvatarUtil { diff --git a/src/main/java/com/jagrosh/vortex/pro/api/URLResolver.java b/src/main/java/com/jagrosh/vortex/pro/api/URLResolver.java index 1903932..4a07a80 100644 --- a/src/main/java/com/jagrosh/vortex/pro/api/URLResolver.java +++ b/src/main/java/com/jagrosh/vortex/pro/api/URLResolver.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 John Grosh (john.a.grosh@gmail.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jagrosh.vortex.pro.api; import com.jagrosh.vortex.pro.ProFeature; @@ -5,6 +20,9 @@ import java.util.List; +/** + * @author Michael Ritter (Kantenkugel) + */ @ProFeature(value = "com.jagrosh.vortex.pro.URLResolver", mock = URLResolverMock.class) public interface URLResolver { diff --git a/src/main/java/com/jagrosh/vortex/pro/api/mocks/URLResolverMock.java b/src/main/java/com/jagrosh/vortex/pro/api/mocks/URLResolverMock.java index 3224d28..84431e1 100644 --- a/src/main/java/com/jagrosh/vortex/pro/api/mocks/URLResolverMock.java +++ b/src/main/java/com/jagrosh/vortex/pro/api/mocks/URLResolverMock.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 John Grosh (john.a.grosh@gmail.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jagrosh.vortex.pro.api.mocks; import com.jagrosh.vortex.pro.api.URLResolver; @@ -5,12 +20,15 @@ import java.util.Collections; import java.util.List; +/** + * @author Michael Ritter (Kantenkugel) + */ public class URLResolverMock implements URLResolver { - public URLResolverMock(String url, String secret){} - @Override - public void loadSafeDomains(){} + public void loadSafeDomains(){ + //empty Mock method + } @Override public List findRedirects(String link)