From 2113bcb241d24adc4e27df2ee6c2df34176fa0c6 Mon Sep 17 00:00:00 2001 From: administrator <1169083089@qq.com> Date: Sat, 9 Apr 2022 11:29:42 +0800 Subject: [PATCH] Put perm nodes & strings to a new class. --- settings.gradle | 2 +- .../ericliu/pixelmonsync/Pixelmonsync.java | 5 +-- .../pixelmonsync/command/Commands.java | 35 ++++++++++--------- .../ericliu/pixelmonsync/pref/Reference.java | 17 +++++++++ 4 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/github/ericliu/pixelmonsync/pref/Reference.java diff --git a/settings.gradle b/settings.gradle index cf7fd15..34082de 100755 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'PixelmonSync2' +rootProject.name = 'PixelmonSync' diff --git a/src/main/java/com/github/ericliu/pixelmonsync/Pixelmonsync.java b/src/main/java/com/github/ericliu/pixelmonsync/Pixelmonsync.java index 8c1276c..52f9af3 100755 --- a/src/main/java/com/github/ericliu/pixelmonsync/Pixelmonsync.java +++ b/src/main/java/com/github/ericliu/pixelmonsync/Pixelmonsync.java @@ -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; @@ -19,8 +20,8 @@ import java.io.File; @Plugin( - id = "pixelmonsync", - name = "Pixelmonsync" + id = Reference.PLUGIN_ID, + name = Reference.PLUGIN_NAME ) public class Pixelmonsync { diff --git a/src/main/java/com/github/ericliu/pixelmonsync/command/Commands.java b/src/main/java/com/github/ericliu/pixelmonsync/command/Commands.java index 9b67036..9fe208a 100755 --- a/src/main/java/com/github/ericliu/pixelmonsync/command/Commands.java +++ b/src/main/java/com/github/ericliu/pixelmonsync/command/Commands.java @@ -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; @@ -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.getOne("player").isPresent()){ Player player = args.getOne("player").get(); SyncHandler.instance.load(player); }else if (src instanceof Player){ @@ -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.getOne("player").isPresent()){ Player player = args.getOne("player").get(); SyncHandler.instance.save(player); }else if (src instanceof Player){ @@ -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.getOne("server").isPresent()) { String serverName = args.getOne("server").get(); SyncHandler.instance.save(((Player) src)); BCHandler.instance.connectToServer(((Player) src), serverName); @@ -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.getOne(Text.of("database")).get(); @@ -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"); } } diff --git a/src/main/java/com/github/ericliu/pixelmonsync/pref/Reference.java b/src/main/java/com/github/ericliu/pixelmonsync/pref/Reference.java new file mode 100644 index 0000000..6d14e1d --- /dev/null +++ b/src/main/java/com/github/ericliu/pixelmonsync/pref/Reference.java @@ -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"; + + +}