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

View File

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

View File

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

View File

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

View File

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