Skip to content

Commit

Permalink
Add manage command
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Dec 15, 2017
1 parent 5fecad5 commit e733ec2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>[2.7.2,)</version>
<version>[2.7.4,)</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
61 changes: 54 additions & 7 deletions src/main/java/com/mengcraft/simpleorm/ORM.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import com.mengcraft.simpleorm.lib.MavenLibrary;
import lombok.SneakyThrows;
import lombok.val;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Arrays;
import java.util.Iterator;

public class ORM extends JavaPlugin {

@Override
Expand Down Expand Up @@ -37,14 +41,57 @@ public void onEnable() {
new MetricsLite(this).start();
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
val manager = EbeanManager.DEFAULT;
val l = manager.map;
if (!l.isEmpty()) {
l.forEach((key, handler) -> sender.sendMessage("[" + key + "] -> " + handler));
public boolean onCommand(CommandSender who, Command command, String label, String[] input) {
if (input.length < 1) {
for (val executor : SubExecutor.values()) {
who.sendMessage('/' + label + executor.usage);
}
} else {
try {
Iterator<String> itr = Arrays.asList(input).iterator();
SubExecutor.valueOf(itr.next().toUpperCase()).exec(who, itr);
return true;
} catch (Exception exc) {
who.sendMessage(ChatColor.RED + exc.toString());
}
}
return false;
}

enum SubExecutor {

LIST("list") {
void exec(CommandSender who, Iterator<String> itr) {
val all = EbeanManager.DEFAULT.map;
if (!all.isEmpty()) {
all.forEach((key, handler) -> who.sendMessage("[" + key + "] -> " + handler));
}
}
},

REMOVE("remove <plugin_name>") {
void exec(CommandSender who, Iterator<String> itr) {
EbeanHandler remove = EbeanManager.DEFAULT.map.remove(itr.next());
who.sendMessage(remove == null ? "handle not found" : "okay");
}
},

REMOVE_ALL("remove_all") {
void exec(CommandSender who, Iterator<String> itr) {
EbeanManager.DEFAULT.map.clear();
who.sendMessage("okay");
}
};

private final String usage;

SubExecutor(String usage) {
this.usage = usage;
}

void exec(CommandSender who, Iterator<String> itr) {
throw new AbstractMethodError("exec");
}
return true;
}

}

0 comments on commit e733ec2

Please sign in to comment.