style(core-bukkit): 修改代码格式

This commit is contained in:
2023-10-19 15:01:34 +08:00
parent b22f33f931
commit 6a45265215
5 changed files with 32 additions and 20 deletions

View File

@@ -13,24 +13,16 @@ import java.util.stream.Collectors;
@SuppressWarnings("unused")
public abstract class ParentCommand extends ChildCommand {
@NotNull
private final String name;
@NotNull
private final List<ChildCommand> childCommands;
public ParentCommand(@NotNull String name) {
this.name = name;
public ParentCommand() {
childCommands = new ArrayList<>();
}
@NotNull
public abstract JavaPlugin getPlugin();
@Override
public @NotNull String getName() {
return name;
}
@Nullable
public ParentCommand getParent() {
return null;
@@ -46,9 +38,9 @@ public abstract class ParentCommand extends ChildCommand {
public String getUsage() {
ParentCommand parent = getParent();
if (parent == null) {
return "/" + name;
return "/" + getName();
}
return parent.getUsage() + " " + name;
return parent.getUsage() + " " + getName();
}
@Override
@@ -103,7 +95,7 @@ public abstract class ParentCommand extends ChildCommand {
}
public void sendHelp(@NotNull CommandSender sender) {
sender.sendMessage("§e==================== [ " + name + " 使用帮助] ====================");
sender.sendMessage("§e==================== [ " + getName() + " 使用帮助] ====================");
Map<String, String> helpMap = getCommandHelp(sender);
int maxLength = helpMap.keySet().stream()
.map(String::length)

View File

@@ -10,7 +10,6 @@ public class ParentCoreCommand extends ParentCommand {
public static final ParentCoreCommand INSTANCE = new ParentCoreCommand();
private ParentCoreCommand() {
super("hamster-core");
addChildCommand(EnvCommand.INSTANCE);
addChildCommand(GCCommand.INSTANCE);
addChildCommand(YamlCommand.INSTANCE);
@@ -20,6 +19,11 @@ public class ParentCoreCommand extends ParentCommand {
addChildCommand(SystemCommand.INSTANCE);
}
@Override
public @NotNull String getName() {
return "hamster-core";
}
@Override
public @NotNull JavaPlugin getPlugin() {
return HamsterCorePlugin.getInstance();

View File

@@ -12,7 +12,6 @@ public final class ParentLoreCommand extends ParentCommand {
public static final ParentLoreCommand INSTANCE = new ParentLoreCommand();
public ParentLoreCommand() {
super("lore");
addChildCommand(LoreAddCommand.INSTANCE);
addChildCommand(LoreRemoveCommand.INSTANCE);
addChildCommand(LoreSetCommand.INSTANCE);
@@ -22,6 +21,11 @@ public final class ParentLoreCommand extends ParentCommand {
addChildCommand(LoreFlagCommand.INSTANCE);
}
@Override
public @NotNull String getName() {
return "lore";
}
@Override
public @NotNull JavaPlugin getPlugin() {
return HamsterCorePlugin.getInstance();

View File

@@ -50,6 +50,7 @@ public enum CoreMessage {
for (CoreMessage value : values()) {
ConfigurationSection section = config.getConfigurationSection(value.name());
if (section == null) {
logger.warning("未找到消息设置: " + value.name());
continue;
}
try {

View File

@@ -241,18 +241,29 @@ public final class CoreBukkitUtils {
return container.toString();
}
@NotNull
public static ItemStack deserializeItemStack(@NotNull String s) {
return NBTItem.convertNBTtoItem(new NBTContainer(s));
@Nullable
public static ItemStack deserializeItemStack(@NotNull String string) {
ItemStack stack;
try {
stack = NBTItem.convertNBTtoItem(new NBTContainer(string));
} catch (Exception ignored) {
stack = null;
}
return stack;
}
@NotNull
public static ItemStack deserializeItemStack(@NotNull String s, @NotNull ItemStack defaultValue) {
public static ItemStack deserializeItemStack(@NotNull String string, @NotNull ItemStack defaultValue) {
ItemStack stack;
try {
return NBTItem.convertNBTtoItem(new NBTContainer(s));
} catch (Exception e) {
stack = NBTItem.convertNBTtoItem(new NBTContainer(string));
} catch (Exception ignored) {
stack = null;
}
if (stack == null) {
return defaultValue;
}
return stack;
}
@NotNull