Skip to content

Commit

Permalink
New Features and Addtions 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
funkemunky committed Jan 22, 2019
1 parent e6a6e3b commit 84fc7f5
Show file tree
Hide file tree
Showing 26 changed files with 254 additions and 210 deletions.
1 change: 1 addition & 0 deletions API/.idea/artifacts/Atlas_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions API/.idea/libraries/nSpigot.xml

This file was deleted.

10 changes: 10 additions & 0 deletions API/.idea/libraries/org_mongodb_mongo_java_driver_3_8_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

348 changes: 181 additions & 167 deletions API/.idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions API/Atlas.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<orderEntry type="library" name="asm-all-5.2" level="project" />
<orderEntry type="library" name="spigot-1.8.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="lombok-1.18.0" level="project" />
<orderEntry type="library" name="org.mongodb:mongo-java-driver:3.8.0" level="project" />
</component>
</module>
Binary file modified API/out/artifacts/Atlas_jar/Atlas.jar
Binary file not shown.
Binary file modified API/out/production/Atlas/cc/funkemunky/api/Atlas.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified API/out/production/Atlas/cc/funkemunky/api/updater/Updater.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified API/out/production/Atlas/cc/funkemunky/api/utils/MathUtils.class
Binary file not shown.
2 changes: 1 addition & 1 deletion API/out/production/Atlas/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Atlas
main: cc.funkemunky.api.Atlas
version: 1.0.5
version: 1.0.6
author: funkemunky
commands:
atlas:
2 changes: 1 addition & 1 deletion API/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Atlas
main: cc.funkemunky.api.Atlas
version: 1.0.5
version: 1.0.6
author: funkemunky
commands:
atlas:
55 changes: 30 additions & 25 deletions API/src/cc/funkemunky/api/Atlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,39 @@ public void initializeScanner(Class<?> mainClass, Plugin plugin) {
ClassScanner.scanFile(null, mainClass).forEach(c -> {
try {
Class clazz = Class.forName(c);
Object obj = clazz.newInstance();

if (obj instanceof Listener) {
MiscUtils.printToConsole("&eFound " + clazz.getSimpleName() + " Bukkit listener. Registering...");
Bukkit.getPluginManager().registerEvents((Listener) obj, plugin);
} else if(obj instanceof cc.funkemunky.api.event.system.Listener) {
MiscUtils.printToConsole("&eFound " + clazz.getSimpleName() + " Atlas listener. Registering...");
EventManager.register((cc.funkemunky.api.event.system.Listener) obj);
}

Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.isAnnotationPresent(ConfigSetting.class)).forEach(field -> {
String path = field.getAnnotation(ConfigSetting.class).path() + "." + field.getName();
try {
field.setAccessible(true);
MiscUtils.printToConsole("&eFound " + field.getName() + " ConfigSetting (default=" + field.get(obj) + ").");
if(plugin.getConfig().get(path) == null) {
MiscUtils.printToConsole("&eValue not found in configuration! Setting default into config...");
plugin.getConfig().set(path, field.get(obj));
saveConfig();
} else {
field.set(obj, plugin.getConfig().get(path));
MiscUtils.printToConsole("&eValue found in configuration! Set value to &a" + plugin.getConfig().get(path));
}
} catch (Exception e) {
e.printStackTrace();
if(clazz.isAnnotationPresent(Init.class)) {
Object obj = clazz.equals(mainClass) ? plugin : clazz.newInstance();

if (obj instanceof Listener) {
MiscUtils.printToConsole("&eFound " + clazz.getSimpleName() + " Bukkit listener. Registering...");
Bukkit.getPluginManager().registerEvents((Listener) obj, plugin);
} else if(obj instanceof cc.funkemunky.api.event.system.Listener) {
MiscUtils.printToConsole("&eFound " + clazz.getSimpleName() + " Atlas listener. Registering...");
EventManager.register((cc.funkemunky.api.event.system.Listener) obj);
}
});

Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.isAnnotationPresent(ConfigSetting.class)).forEach(field -> {
String name = field.getAnnotation(ConfigSetting.class).name();
String path = field.getAnnotation(ConfigSetting.class).path() + "." + (name.length() > 0 ? name : field.getName());
try {
field.setAccessible(true);
MiscUtils.printToConsole("&eFound " + field.getName() + " ConfigSetting (default=" + field.get(obj) + ").");
if(plugin.getConfig().get(path) == null) {
MiscUtils.printToConsole("&eValue not found in configuration! Setting default into config...");
plugin.getConfig().set(path, field.get(obj));
plugin.saveConfig();
} else {
field.set(obj, plugin.getConfig().get(path));

MiscUtils.printToConsole("&eValue found in configuration! Set value to &a" + plugin.getConfig().get(path));
}
} catch (Exception e) {
e.printStackTrace();
}
});

}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
6 changes: 6 additions & 0 deletions API/src/cc/funkemunky/api/commands/FunkeArgument.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package cc.funkemunky.api.commands;

import lombok.Getter;
import lombok.Setter;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import java.util.*;

@Getter
@Setter
public abstract class FunkeArgument {
private FunkeCommand parent;
private String name, display, description;
private boolean playerOnly;
private List<String> aliases = new ArrayList<>();
private Map<Integer, List<String>> tabComplete = new HashMap<>();
private String[] permission;
Expand All @@ -19,6 +22,8 @@ public FunkeArgument(FunkeCommand parent, String name, String display, String de
this.name = name;
this.display = display;
this.description = description;

playerOnly = false;
}

public FunkeArgument(FunkeCommand parent, String name, String display, String description, String... permission) {
Expand All @@ -27,6 +32,7 @@ public FunkeArgument(FunkeCommand parent, String name, String display, String de
this.display = display;
this.description = description;
this.permission = permission;
playerOnly = false;
}

public void addAlias(String alias) {
Expand Down
6 changes: 5 additions & 1 deletion API/src/cc/funkemunky/api/commands/FunkeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

if ((argument.getPermission() == null || sender.hasPermission(adminPerm)
|| sender.hasPermission(permission))) {
argument.onArgument(sender, cmd, args);
if(!argument.isPlayerOnly() || sender instanceof Player) {
argument.onArgument(sender, cmd, args);
} else {
sender.sendMessage(commandMessages.getErrorColor() + commandMessages.getPlayerOnly());
}
break;
}
sender.sendMessage(commandMessages.getErrorColor() + commandMessages.getNoPermission());
Expand Down
11 changes: 10 additions & 1 deletion API/src/cc/funkemunky/api/commands/FunkeCommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

@Getter
public class FunkeCommandManager {
private final List<FunkeCommand> commands;

public FunkeCommandManager() {
commands = new ArrayList<>();
commands = new CopyOnWriteArrayList<>();
}

public void addCommand(FunkeCommand command) {
Expand All @@ -20,5 +21,13 @@ public void addCommand(FunkeCommand command) {
public void removeAllCommands() {
commands.clear();
}

public void removeCommand(String name) {
commands.stream().filter(cmd -> cmd.getName().equalsIgnoreCase(name)).forEach(commands::remove);
}

public void removeCommand(FunkeCommand command) {
commands.remove(command);
}
}

2 changes: 1 addition & 1 deletion API/src/cc/funkemunky/api/updater/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Getter
public class Updater {
private int update = - 1, currentUpdate = 6;
private int update = - 1, currentUpdate = 7;
private String version, downloadLink;
private File pluginLocation;
private boolean importantUpdate = false;
Expand Down
4 changes: 2 additions & 2 deletions API/src/cc/funkemunky/api/utils/ClassScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static void scanPath(String file, Path path, Set<String> plugins) {
}
}

public static void scanDirectory(String file, Path dir, final Set<String> plugins) {
private static void scanDirectory(String file, Path dir, final Set<String> plugins) {
try {
Files.walkFileTree(dir, newHashSet(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
@Override
Expand Down Expand Up @@ -143,7 +143,7 @@ public static String findPlugin(String file, InputStream in) {
}
if (classNode.superName != null && (classNode.superName.equals(file))) return className;
} catch (Exception e) {
System.out.println("Failed to scan: " + in.toString());
//System.out.println("Failed to scan: " + in.toString());
}
return null;
}
Expand Down
1 change: 1 addition & 0 deletions API/src/cc/funkemunky/api/utils/ConfigSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@Target({ElementType.FIELD, ElementType.TYPE})
public @interface ConfigSetting {
String path() default "";
String name() default "";
}
4 changes: 4 additions & 0 deletions API/src/cc/funkemunky/api/utils/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static boolean playerMoved(Location from, Location to) {
return playerMoved(from.toVector(), to.toVector());
}

public static boolean approxEquals(double accuracy, double... equals) {
return MathUtils.getDelta(Arrays.stream(equals).sum() / equals.length, equals[0]) < accuracy;
}

private static long gcd(long x, long y) {
return (y == 0) ? x : gcd(y, x % y);
}
Expand Down

0 comments on commit 84fc7f5

Please sign in to comment.