Skip to content

Commit

Permalink
[1.8.6-dev3]craft list命令权限细化,添加工作台配方创建的非空判定
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Jan 5, 2024
1 parent fe228dc commit 3deaec2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.8.6-dev2"
version = "1.8.6-dev3"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ protected AbstractSubCommand(String command) {

@Override
public boolean onCommand(CommandSender sender, List<String> args) {
if (args.isEmpty()) {
sendNotEnoughCmdParamMsg(sender, 1);
return true;
}
SubcmdExecutor subCommand = subcommands().get(args.get(0));
if (subCommand == null) {
LangUtil.sendLang(sender, Languages.COMMAND_UNDEFINED_SUBCMD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.*;

import static crypticlib.command.CommandManager.subcommand;

public final class RecipeListCommand extends AbstractSubCommand {

Expand All @@ -22,42 +21,29 @@ public final class RecipeListCommand extends AbstractSubCommand {

private RecipeListCommand() {
super("list", "craftorithm.command.list");
regSub(subcommand(SERVER)
.setPermission("craftorithm.command.list.server")
.setExecutor((sender, args) -> {
new RecipeListMenu((Player) sender, RecipeManager.INSTANCE.serverRecipesCache().keySet()).openMenu();
return true;
}));
regSub(subcommand(CRAFTORITHM)
.setPermission("craftorithm.command.list.craftorithm")
.setExecutor((sender, arg) -> {
new RecipeGroupListMenu((Player) sender).openMenu();
return true;
}));
}

@Override
public boolean onCommand(CommandSender sender, List<String> args) {
if (CrypticLib.minecraftVersion() < 11600) {
LangUtil.sendLang(sender, Languages.COMMAND_LIST_UNSUPPORTED_VERSION);
return true;
}
if (!checkSenderIsPlayer(sender)) {
return true;
}
String listType;
if (args.isEmpty())
listType = CRAFTORITHM;
else
listType = args.get(0).toLowerCase(Locale.ENGLISH);
Player player = (Player) sender;
switch (listType) {
case SERVER:
new RecipeListMenu(player, RecipeManager.INSTANCE.serverRecipesCache().keySet()).openMenu();
break;
case CRAFTORITHM:
default:
new RecipeGroupListMenu(player).openMenu();
break;
if (args.isEmpty()) {
args = new ArrayList<>(Collections.singletonList(CRAFTORITHM));
}
return true;
return super.onCommand(sender, args);
}

@Override
public List<String> onTabComplete(CommandSender sender, List<String> args) {
if (args.size() <= 1) {
List<String> list = new ArrayList<>(Arrays.asList(CRAFTORITHM, SERVER));
filterTabList(list, args.get(0));
return list;
}
return super.onTabComplete(sender, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public CraftingRecipeCreator(@NotNull Player player, RecipeType recipeType, @Not
String sourceName = ItemUtils.matchItemNameOrCreate(source, true);
sourceList.add(sourceName);
}
boolean allEmpty = true;
for (String choice : sourceList) {
if (!choice.isEmpty()) {
allEmpty = false;
break;
}
}
if (allEmpty) {
LangUtil.sendLang(event.getWhoClicked(), Languages.COMMAND_CREATE_NULL_SOURCE);
return;
}
ConfigWrapper recipeConfig = createRecipeConfig(recipeName);
switch (recipeType()) {
case SHAPED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void reloadRecipeManager() {
loadRecipeGroups();
loadRecipes();
reloadRemovedRecipes();
reloadServerRecipeCache();
loadServerRecipeCache();
}

private void loadRecipes() {
Expand Down Expand Up @@ -444,7 +444,7 @@ public void resetRecipes() {
recipeUnlockMap.clear();
}

public void reloadServerRecipeCache() {
public void loadServerRecipeCache() {
Iterator<Recipe> recipeIterator = Bukkit.recipeIterator();
serverRecipesCache.clear();
while (recipeIterator.hasNext()) {
Expand Down

0 comments on commit 3deaec2

Please sign in to comment.