From 7f90dabcc02f275500bcae7865940976b4d8c77c Mon Sep 17 00:00:00 2001 From: Slqmy <90862990+Slqmy@users.noreply.github.com> Date: Sat, 10 Aug 2024 22:25:09 +0100 Subject: [PATCH] Use method lambda --- .../commands/GiveCustomItemCommand.java | 17 +++++++---------- .../commands/SpawnCustomEntityCommand.java | 17 +++++++---------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/slqmy/template_paper_plugin/commands/GiveCustomItemCommand.java b/src/main/java/net/slqmy/template_paper_plugin/commands/GiveCustomItemCommand.java index 1a26b38a..03496af9 100644 --- a/src/main/java/net/slqmy/template_paper_plugin/commands/GiveCustomItemCommand.java +++ b/src/main/java/net/slqmy/template_paper_plugin/commands/GiveCustomItemCommand.java @@ -28,16 +28,13 @@ public GiveCustomItemCommand(TemplatePaperPlugin plugin) { String[] customItemIds = Stream.of(CustomItem.values()).map((customItem) -> customItem.name()).toArray(String[]::new); - Argument customItemArgument = new CustomArgument(new StringArgument(customItemArgumentNodeName), new CustomArgumentInfoParser<>() { - @Override - public CustomItem apply(CustomArgumentInfo info) throws CustomArgumentException { - String input = info.currentInput(); - - try { - return CustomItem.valueOf(input); - } catch (IllegalArgumentException exception) { - throw CustomArgumentException.fromAdventureComponent(plugin.getLanguageManager().getMessage(Message.UNKNOWN_CUSTOM_ITEM, info.sender(), input)); - } + Argument customItemArgument = new CustomArgument(new StringArgument(customItemArgumentNodeName), (CustomArgumentInfo info) -> { + String input = info.currentInput(); + + try { + return CustomItem.valueOf(input); + } catch (IllegalArgumentException exception) { + throw CustomArgumentException.fromAdventureComponent(plugin.getLanguageManager().getMessage(Message.UNKNOWN_CUSTOM_ITEM, info.sender(), input)); } }).includeSuggestions(ArgumentSuggestions.strings(customItemIds)); diff --git a/src/main/java/net/slqmy/template_paper_plugin/commands/SpawnCustomEntityCommand.java b/src/main/java/net/slqmy/template_paper_plugin/commands/SpawnCustomEntityCommand.java index 3457dc47..4dfbe610 100644 --- a/src/main/java/net/slqmy/template_paper_plugin/commands/SpawnCustomEntityCommand.java +++ b/src/main/java/net/slqmy/template_paper_plugin/commands/SpawnCustomEntityCommand.java @@ -28,16 +28,13 @@ public SpawnCustomEntityCommand(TemplatePaperPlugin plugin) { String[] customEntityIds = Stream.of(CustomEntity.values()).map((customEntity) -> customEntity.name()).toArray(String[]::new); - Argument customEntityArgument = new CustomArgument(new StringArgument(customEntityArgumentNodeName), new CustomArgumentInfoParser<>() { - @Override - public CustomEntity apply(CustomArgumentInfo info) throws CustomArgumentException { - String input = info.currentInput(); - - try { - return CustomEntity.valueOf(input); - } catch (IllegalArgumentException exception) { - throw CustomArgumentException.fromAdventureComponent(plugin.getLanguageManager().getMessage(Message.UNKNOWN_CUSTOM_ENTITY, info.sender(), input)); - } + Argument customEntityArgument = new CustomArgument(new StringArgument(customEntityArgumentNodeName), (CustomArgumentInfo info) -> { + String input = info.currentInput(); + + try { + return CustomEntity.valueOf(input); + } catch (IllegalArgumentException exception) { + throw CustomArgumentException.fromAdventureComponent(plugin.getLanguageManager().getMessage(Message.UNKNOWN_CUSTOM_ENTITY, info.sender(), input)); } }).includeSuggestions(ArgumentSuggestions.strings(customEntityIds));