Skip to content

Commit

Permalink
优化代码结构
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiyodaXiaoYi committed Nov 16, 2023
1 parent d36b113 commit 8c5c95b
Show file tree
Hide file tree
Showing 28 changed files with 257 additions and 263 deletions.
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.text.SimpleDateFormat

plugins {
Expand Down Expand Up @@ -34,11 +33,11 @@ dependencies {
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.5.0b")
compileOnly("com.github.oraxen:oraxen:1.160.0")
compileOnly("io.lumine:Mythic-Dist:5.3.5")
implementation("com.crypticlib:CrypticLib:0.1.4")
implementation("com.crypticlib:CrypticLib:0.1.6")
}

group = "com.github.yufiriamazenta"
version = "1.4.7-dev1"
version = "1.4.7-dev2"
var pluginVersion: String = version.toString() + "-" + SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis())
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.github.yufiriamazenta.craftorithm.bstat.Metrics;
import com.github.yufiriamazenta.craftorithm.config.ConfigUpdater;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.listener.*;
import com.github.yufiriamazenta.craftorithm.menu.bukkit.BukkitMenuDispatcher;
import com.github.yufiriamazenta.craftorithm.listener.FurnaceSmeltHandler;
import com.github.yufiriamazenta.craftorithm.listener.SmithingHandler;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public StringArcencielBlock(String arcencielBlockBody) {
public ReturnObj<Object> exec(Player player) {
List<String> scriptChain = new ArrayList<>(Arrays.asList(arcencielBlockBody.split(" ")));
scriptChain.removeIf(String::isEmpty);
if (scriptChain.size() < 1)
if (scriptChain.isEmpty())
return new ReturnObj<>(ArcencielSignal.CONTINUE, null);
String keywordStr = scriptChain.get(0);
IArcencielToken<?> keyword = arcencielKeywordMap.get(keywordStr);
if (keyword == null) {
List<String> func = ArcencielDispatcher.INSTANCE.getFunc(keywordStr);
if (func.size() < 1) {
LangUtil.sendMsg(player, "arcenciel.unknown_token", ContainerUtil.newHashMap("<token>", keywordStr));
if (func.isEmpty()) {
LangUtil.sendLang(player, "arcenciel.unknown_token", ContainerUtil.newHashMap("<token>", keywordStr));
return new ReturnObj<>(ArcencielSignal.CONTINUE);
} else {
return ArcencielDispatcher.INSTANCE.dispatchArcencielFunc(player, func);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ protected TokenHasPerm() {

@Override
public ReturnObj<Boolean> exec(Player player, List<String> args) {
if (args.size() < 1) {
LangUtil.sendMsg(player, "arcenciel.not_enough_param", ContainerUtil.newHashMap("<statement>", "if"));
if (args.isEmpty()) {
LangUtil.sendLang(player, "arcenciel.not_enough_param", ContainerUtil.newHashMap("<statement>", "if"));
return new ReturnObj<>(false);
}
return new ReturnObj<>(player.hasPermission(args.get(0)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.yufiriamazenta.craftorithm.bstat;

import com.github.yufiriamazenta.craftorithm.Craftorithm;
import crypticlib.CrypticLib;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@BukkitCommand(
Expand All @@ -31,25 +33,25 @@ public enum PluginCommand implements IPluginCmdExecutor {
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
List<String> argList = Arrays.asList(args);
if (argList.isEmpty()) {
LangUtil.sendMsg(sender, "command.not_enough_param", ContainerUtil.newHashMap("<number>", String.valueOf(1)));
LangUtil.sendLang(sender, "command.not_enough_param", ContainerUtil.newHashMap("<number>", String.valueOf(1)));
return true;
}
ISubCmdExecutor subCommand = subCommandMap.get(argList.get(0));
if (subCommand != null) {
String perm = subCommand.permission();
if (perm != null) {
if (!sender.hasPermission(perm)) {
LangUtil.sendMsg(sender, "command.no_perm");
LangUtil.sendLang(sender, "command.no_perm");
return true;
}
}
return subCommand.onCommand(sender, argList.subList(1, argList.size()));
}
else {
LangUtil.sendMsg(sender, "command.undefined_subcmd");
LangUtil.sendLang(sender, "command.undefined_subcmd");
return true;
}
}
Expand All @@ -60,8 +62,9 @@ private void regDefaultSubCommands() {
regSubCommand(RemoveRecipeCommand.INSTANCE);
regSubCommand(ItemCommand.INSTANCE);
regSubCommand(RunArcencielCmd.INSTANCE);
regSubCommand(LookRecipeCommand.INSTANCE);
regSubCommand(ShowRecipeCommand.INSTANCE);
regSubCommand(CreateRecipeCommand.INSTANCE);
regSubCommand(RecipeListCommand.INSTANCE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class AbstractSubCommand implements ISubCmdExecutor {

private final String command;
private String perm;
private final String perm;
private Map<String, ISubCmdExecutor> subCommandMap;

protected AbstractSubCommand(String command, Map<String, ISubCmdExecutor> subCommandMap, String perm) {
Expand All @@ -37,12 +35,12 @@ protected AbstractSubCommand(String command) {
public boolean onCommand(CommandSender sender, List<String> args) {
ISubCmdExecutor subCommand = subCommandMap.get(args.get(0));
if (subCommand == null) {
LangUtil.sendMsg(sender, "command.undefined_subcmd");
LangUtil.sendLang(sender, "command.undefined_subcmd");
} else {
String perm = subCommand.permission();
if (perm != null) {
if (!sender.hasPermission(perm)) {
LangUtil.sendMsg(sender, "command.no_perm");
LangUtil.sendLang(sender, "command.no_perm");
return true;
}
}
Expand Down Expand Up @@ -70,14 +68,14 @@ public void sendNotEnoughCmdParamMsg(CommandSender sender, int paramNum) {
}

public void sendNotEnoughCmdParamMsg(CommandSender sender, String paramStr) {
LangUtil.sendMsg(sender, "command.not_enough_param", ContainerUtil.newHashMap("<number>", paramStr));
LangUtil.sendLang(sender, "command.not_enough_param", ContainerUtil.newHashMap("<number>", paramStr));
}

public boolean checkSenderIsPlayer(CommandSender sender) {
if (sender instanceof Player) {
return true;
} else {
LangUtil.sendMsg(sender, "command.player_only");
LangUtil.sendLang(sender, "command.player_only");
return false;
}
}
Expand All @@ -91,8 +89,6 @@ public String permission() {
return perm;
}

public void setPerm() {
this.perm = perm;
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.yufiriamazenta.craftorithm.cmd.subcmd;

import com.github.yufiriamazenta.craftorithm.Craftorithm;
import com.github.yufiriamazenta.craftorithm.menu.impl.recipe.RecipeCreatorMenuHolder;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeType;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
Expand All @@ -13,13 +12,13 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class CreateRecipeCommand extends AbstractSubCommand {
public final class CreateRecipeCommand extends AbstractSubCommand {

public static final CreateRecipeCommand INSTANCE = new CreateRecipeCommand();
private final List<String> recipeTypeList;
private final Pattern recipeNamePattern = Pattern.compile("[a-z0-9/._-]+");

protected CreateRecipeCommand() {
private CreateRecipeCommand() {
super("create", "craftorithm.command.create");
recipeTypeList = Arrays.stream(RecipeType.values()).map(RecipeType::name).map(s -> s.toLowerCase(Locale.ROOT)).collect(Collectors.toList());
List<String> unsupportedRecipeTypeList = new ArrayList<>();
Expand All @@ -44,13 +43,13 @@ public boolean onCommand(CommandSender sender, List<String> args) {
}
String recipeTypeStr = args.get(0).toLowerCase(Locale.ROOT);
if (!recipeTypeList.contains(recipeTypeStr)) {
LangUtil.sendMsg(sender, "command.create.unsupported_recipe_type");
LangUtil.sendLang(sender, "command.create.unsupported_recipe_type");
return true;
}
String recipeName = args.get(1);
Matcher matcher = recipeNamePattern.matcher(recipeName);
if (!matcher.matches()) {
LangUtil.sendMsg(sender, "command.create.unsupported_recipe_name");
LangUtil.sendLang(sender, "command.create.unsupported_recipe_name");
return true;
}
RecipeType recipeType = RecipeType.valueOf(recipeTypeStr.toUpperCase(Locale.ROOT));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.yufiriamazenta.craftorithm.cmd.subcmd;

import com.github.yufiriamazenta.craftorithm.menu.impl.recipe.RecipeListMenuHolder;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

//TODO 展示全服所有配方
public final class RecipeListCommand extends AbstractSubCommand {

public static final RecipeListCommand INSTANCE = new RecipeListCommand();

private RecipeListCommand() {
super("list", "craftorithm.command.list");
}

@Override
public boolean onCommand(CommandSender sender, List<String> args) {
if (!checkSenderIsPlayer(sender)) {
LangUtil.sendLang(sender, "command.player_only");
return true;
}
Player player = (Player) sender;
player.openInventory(new RecipeListMenuHolder().getInventory());
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ private ReloadCommand() {
public boolean onCommand(CommandSender sender, List<String> args) {
try {
reloadPlugin();
LangUtil.sendMsg(sender, "command.reload.success");
LangUtil.sendLang(sender, "command.reload.success");
} catch (Exception e) {
e.printStackTrace();
LangUtil.sendMsg(sender, "command.reload.exception");
LangUtil.sendLang(sender, "command.reload.exception");
}
return true;
}
Expand All @@ -40,7 +40,7 @@ public static void reloadPlugin() {
public static void reloadConfigs() {
Craftorithm.getInstance().reloadConfig();
LangUtil.reloadMsgConfig();
RemoveRecipeCommand.getRemovedRecipeConfig().reloadConfig();
RecipeManager.getRemovedRecipeConfig().reloadConfig();
ItemManager.loadItemFiles();
RecipeManager.loadRecipeFiles();
ArcencielDispatcher.INSTANCE.getFunctionFile().reloadConfig();
Expand Down
Loading

0 comments on commit 8c5c95b

Please sign in to comment.