Skip to content

Commit

Permalink
Put perm nodes & strings to a new class.
Browse files Browse the repository at this point in the history
  • Loading branch information
wujichen158 committed Apr 9, 2022
1 parent 6877299 commit 2113bcb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'PixelmonSync2'
rootProject.name = 'PixelmonSync'
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.github.ericliu.pixelmonsync.handler.DatabaseManger;
import com.github.ericliu.pixelmonsync.handler.EventHandler;
import com.github.ericliu.pixelmonsync.handler.SyncHandler;
import com.github.ericliu.pixelmonsync.pref.Reference;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
Expand All @@ -19,8 +20,8 @@
import java.io.File;

@Plugin(
id = "pixelmonsync",
name = "Pixelmonsync"
id = Reference.PLUGIN_ID,
name = Reference.PLUGIN_NAME
)
public class Pixelmonsync {

Expand Down
35 changes: 18 additions & 17 deletions src/main/java/com/github/ericliu/pixelmonsync/command/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.ericliu.pixelmonsync.handler.BCHandler;
import com.github.ericliu.pixelmonsync.handler.MigrateHandler;
import com.github.ericliu.pixelmonsync.handler.SyncHandler;
import com.github.ericliu.pixelmonsync.pref.Reference;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.args.GenericArguments;
Expand All @@ -13,10 +14,10 @@

public class Commands {

private final static CommandSpec load =
private final static CommandSpec LOAD =
CommandSpec.builder()
.executor(((src, args) -> {
if (args.hasAny("player")){
if (args.hasAny("player") && args.<Player>getOne("player").isPresent()){
Player player = args.<Player>getOne("player").get();
SyncHandler.instance.load(player);
}else if (src instanceof Player){
Expand All @@ -30,13 +31,13 @@ public class Commands {
GenericArguments.player(Text.of("player"))
)
)
.permission("pixelmonsync.load")
.permission(Reference.PERM_NODE_LOAD)
.build();

private final static CommandSpec save =
private final static CommandSpec SAVE =
CommandSpec.builder()
.executor(((src, args) -> {
if (args.hasAny("player")){
if (args.hasAny("player") && args.<Player>getOne("player").isPresent()){
Player player = args.<Player>getOne("player").get();
SyncHandler.instance.save(player);
}else if (src instanceof Player){
Expand All @@ -50,13 +51,13 @@ public class Commands {
GenericArguments.player(Text.of("player"))
)
)
.permission("pixelmonsync.save")
.permission(Reference.PERM_NODE_SAVE)
.build();

private final static CommandSpec server =
private final static CommandSpec SERVER =
CommandSpec.builder()
.executor(((src, args) -> {
if (src instanceof Player) {
if (src instanceof Player && args.<String>getOne("server").isPresent()) {
String serverName = args.<String>getOne("server").get();
SyncHandler.instance.save(((Player) src));
BCHandler.instance.connectToServer(((Player) src), serverName);
Expand All @@ -66,10 +67,10 @@ public class Commands {
.arguments(
GenericArguments.string(Text.of("server"))
)
.permission("pixelmonsync.server")
.permission(Reference.PERM_NODE_SERVER)
.build();

private final static CommandSpec migrate =
private final static CommandSpec MIGRATE =
CommandSpec.builder()
.executor(((src, args) -> {
String database = args.<String>getOne(Text.of("database")).get();
Expand All @@ -83,23 +84,23 @@ public class Commands {
GenericArguments.string(Text.of("database"))
)
)
.permission("pixelmonsync.migrate")
.permission(Reference.PERM_NODE_MIGRATE)
.build();


private final static CommandSpec base =
private final static CommandSpec BASE =
CommandSpec.builder()
.executor(((src, args) -> {
return CommandResult.success();
}))
.child(load, "load")
.child(save, "save")
.child(server, "server")
.child(migrate, "migrate")
.child(LOAD, "load")
.child(SAVE, "save")
.child(SERVER, "server")
.child(MIGRATE, "migrate")
.build();

public Commands(){
Sponge.getCommandManager().register(Pixelmonsync.instance, base, "psync");
Sponge.getCommandManager().register(Pixelmonsync.instance, BASE, "psync");
}

}
17 changes: 17 additions & 0 deletions src/main/java/com/github/ericliu/pixelmonsync/pref/Reference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.ericliu.pixelmonsync.pref;

public class Reference {

public static final String PLUGIN_ID = "pixelmonsync";
public static final String PLUGIN_NAME = "Pixelmonsync";

public static final String USER_NODE = "user";
public static final String ADMIN_NODE = "admin";

public static final String PERM_NODE_LOAD = PLUGIN_ID + "." + ADMIN_NODE + "." + "load";
public static final String PERM_NODE_SAVE = PLUGIN_ID + "." + ADMIN_NODE + "." + "save";
public static final String PERM_NODE_SERVER = PLUGIN_ID + "." + ADMIN_NODE + "." + "server";
public static final String PERM_NODE_MIGRATE = PLUGIN_ID + "." + ADMIN_NODE + "." + "migrate";


}

0 comments on commit 2113bcb

Please sign in to comment.