-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cb4775
commit 889edcf
Showing
9 changed files
with
136 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 91 additions & 42 deletions
133
src/main/java/com/github/yufiriamazenta/craftorithm/cmd/PluginCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,119 @@ | ||
package com.github.yufiriamazenta.craftorithm.cmd; | ||
|
||
import com.github.yufiriamazenta.craftorithm.cmd.sub.ReloadCommand; | ||
import com.github.yufiriamazenta.craftorithm.cmd.sub.RunArcencielCmd; | ||
import com.github.yufiriamazenta.craftorithm.cmd.sub.VersionCommand; | ||
import com.github.yufiriamazenta.craftorithm.Craftorithm; | ||
import com.github.yufiriamazenta.craftorithm.arcenciel.ArcencielDispatcher; | ||
import com.github.yufiriamazenta.craftorithm.cmd.sub.item.ItemCommand; | ||
import com.github.yufiriamazenta.craftorithm.cmd.sub.recipe.CreateRecipeCommand; | ||
import com.github.yufiriamazenta.craftorithm.cmd.sub.recipe.DisableRecipeCommand; | ||
import com.github.yufiriamazenta.craftorithm.cmd.sub.recipe.RecipeListCommand; | ||
import com.github.yufiriamazenta.craftorithm.cmd.sub.recipe.RemoveRecipeCommand; | ||
import com.github.yufiriamazenta.craftorithm.config.Languages; | ||
import com.github.yufiriamazenta.craftorithm.item.ItemManager; | ||
import com.github.yufiriamazenta.craftorithm.item.impl.CraftorithmItemProvider; | ||
import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager; | ||
import com.github.yufiriamazenta.craftorithm.util.CollectionsUtil; | ||
import com.github.yufiriamazenta.craftorithm.util.ItemUtils; | ||
import com.github.yufiriamazenta.craftorithm.util.LangUtil; | ||
import crypticlib.command.BukkitCommand; | ||
import crypticlib.command.RootCmdExecutor; | ||
import crypticlib.command.SubcmdExecutor; | ||
import org.bukkit.command.Command; | ||
import crypticlib.command.CommandTreeInfo; | ||
import crypticlib.command.CommandTreeNode; | ||
import crypticlib.command.CommandTreeRoot; | ||
import crypticlib.command.annotation.CommandNode; | ||
import crypticlib.command.annotation.CommandTree; | ||
import crypticlib.perm.PermInfo; | ||
import org.bukkit.command.CommandSender; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.bukkit.entity.Item; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.StringJoiner; | ||
|
||
@BukkitCommand( | ||
name = "craftorithm", | ||
aliases = {"craft", "cra"}, | ||
permission = "craftorithm.command" | ||
) | ||
public class PluginCommand extends RootCmdExecutor { | ||
@CommandTree | ||
public class PluginCommand extends CommandTreeRoot { | ||
|
||
PluginCommand() { | ||
regDefaultSubCommands(); | ||
super(new CommandTreeInfo("craftorithm", new PermInfo("craftorithm.command"), new String[]{"craft", "cra"})); | ||
setExecutor((sender, args) -> { | ||
LangUtil.sendLang(sender, Languages.COMMAND_UNDEFINED_SUBCMD); | ||
return true; | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { | ||
List<String> argList = Arrays.asList(args); | ||
if (argList.isEmpty()) { | ||
LangUtil.sendLang(sender, Languages.COMMAND_NOT_ENOUGH_PARAM, CollectionsUtil.newStringHashMap("<number>", String.valueOf(1))); | ||
@CommandNode | ||
private CommandTreeNode reload = new CommandTreeNode( | ||
new CommandTreeNode.NodeInfo("reload", new PermInfo("craftorithm.command.reload")), | ||
(sender, args) -> { | ||
try { | ||
Craftorithm.instance().reloadConfig(); | ||
ItemUtils.reloadCannotCraftLore(); | ||
ArcencielDispatcher.INSTANCE.functionFile().reloadConfig(); | ||
CraftorithmItemProvider.INSTANCE.reloadItemProvider(); | ||
ItemManager.INSTANCE.reloadCustomCookingFuel(); | ||
RecipeManager.INSTANCE.reloadRecipeManager(); | ||
LangUtil.sendLang(sender, Languages.COMMAND_RELOAD_SUCCESS); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
LangUtil.sendLang(sender, Languages.COMMAND_RELOAD_EXCEPTION); | ||
} | ||
return true; | ||
} | ||
SubcmdExecutor subCommand = subcommands().get(argList.get(0)); | ||
if (subCommand != null) { | ||
String perm = subCommand.permission(); | ||
if (perm != null) { | ||
if (!sender.hasPermission(perm)) { | ||
LangUtil.sendLang(sender, Languages.COMMAND_NO_PERM); | ||
return true; | ||
} | ||
); | ||
|
||
@CommandNode | ||
private CommandTreeNode version = new CommandTreeNode( | ||
new CommandTreeNode.NodeInfo("version",new PermInfo("craftorithm.command.version")), | ||
(sender, args) -> { | ||
LangUtil.sendLang(sender, Languages.COMMAND_VERSION); | ||
return true; | ||
} | ||
); | ||
|
||
@CommandNode | ||
private CommandTreeNode run = new CommandTreeNode( | ||
new CommandTreeNode.NodeInfo("run", new PermInfo("craftorithm.command.run")), | ||
(sender, args) -> { | ||
if (!checkSenderIsPlayer(sender)) | ||
return true; | ||
if (args.isEmpty()) { | ||
sendNotEnoughCmdParamMsg(sender, 1); | ||
return true; | ||
} | ||
return subCommand.onCommand(sender, argList.subList(1, argList.size())); | ||
long startTime = System.currentTimeMillis(); | ||
StringJoiner arcencielBlock = new StringJoiner(" "); | ||
for (String arg : args) { | ||
arcencielBlock.add(arg); | ||
} | ||
ArcencielDispatcher.INSTANCE.dispatchArcencielBlock((Player) sender, arcencielBlock.toString()); | ||
long execTime = System.currentTimeMillis() - startTime; | ||
LangUtil.sendLang(sender, Languages.COMMAND_RUN_ARCENCIEL_SUCCESS, CollectionsUtil.newStringHashMap("<time>", String.valueOf(execTime))); | ||
return true; | ||
} | ||
else { | ||
LangUtil.sendLang(sender, Languages.COMMAND_UNDEFINED_SUBCMD); | ||
); | ||
|
||
@CommandNode | ||
private CommandTreeNode item = ItemCommand.INSTANCE; | ||
@CommandNode | ||
private CommandTreeNode disable = DisableRecipeCommand.INSTANCE; | ||
@CommandNode | ||
private CommandTreeNode removeRecipe = RemoveRecipeCommand.INSTANCE; | ||
@CommandNode | ||
private CommandTreeNode createRecipe = CreateRecipeCommand.INSTANCE; | ||
@CommandNode | ||
private CommandTreeNode recipeList = RecipeListCommand.INSTANCE; | ||
|
||
public boolean checkSenderIsPlayer(CommandSender sender) { | ||
if (sender instanceof Player) { | ||
return true; | ||
} else { | ||
LangUtil.sendLang(sender, Languages.COMMAND_PLAYER_ONLY); | ||
return false; | ||
} | ||
} | ||
|
||
private void regDefaultSubCommands() { | ||
regSub(ReloadCommand.INSTANCE) | ||
.regSub(VersionCommand.INSTANCE) | ||
.regSub(RemoveRecipeCommand.INSTANCE) | ||
.regSub(DisableRecipeCommand.INSTANCE) | ||
.regSub(ItemCommand.INSTANCE) | ||
.regSub(RunArcencielCmd.INSTANCE) | ||
.regSub(CreateRecipeCommand.INSTANCE) | ||
.regSub(RecipeListCommand.INSTANCE); | ||
public void sendNotEnoughCmdParamMsg(CommandSender sender, int paramNum) { | ||
sendNotEnoughCmdParamMsg(sender, String.valueOf(paramNum)); | ||
} | ||
|
||
public void sendNotEnoughCmdParamMsg(CommandSender sender, String paramStr) { | ||
LangUtil.sendLang(sender, Languages.COMMAND_NOT_ENOUGH_PARAM, CollectionsUtil.newStringHashMap("<number>", paramStr)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/ReloadCommand.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/RunArcencielCmd.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/VersionCommand.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/item/fuel/FuelCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package com.github.yufiriamazenta.craftorithm.cmd.sub.item.fuel; | ||
|
||
import com.github.yufiriamazenta.craftorithm.cmd.sub.AbstractSubCommand; | ||
import crypticlib.command.CommandTreeNode; | ||
import crypticlib.command.annotation.CommandNode; | ||
|
||
public class FuelCommand extends AbstractSubCommand { | ||
|
||
public static final FuelCommand INSTANCE = new FuelCommand(); | ||
@CommandNode | ||
private CommandTreeNode add = AddFuelCommand.INSTANCE; | ||
@CommandNode | ||
private CommandTreeNode remove = RemoveFuelCommand.INSTANCE; | ||
|
||
protected FuelCommand() { | ||
super("fuel", "craftorithm.command.item.fuel"); | ||
regSub(AddFuelCommand.INSTANCE).regSub(RemoveFuelCommand.INSTANCE); | ||
} | ||
|
||
} |
Oops, something went wrong.