-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add PlayerArgument for replace standard argument from litecommands, and fix /tp command usage. * Remove unnecessary <world> in DescriptionDocs annotation.
- Loading branch information
Showing
2 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...e-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/PlayerArgument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.eternalcode.core.bridge.litecommand.argument; | ||
|
||
import com.eternalcode.core.injector.annotations.Inject; | ||
import com.eternalcode.core.injector.annotations.lite.LiteArgument; | ||
import com.eternalcode.core.translation.Translation; | ||
import com.eternalcode.core.translation.TranslationManager; | ||
import com.eternalcode.core.viewer.ViewerProvider; | ||
import dev.rollczi.litecommands.argument.Argument; | ||
import dev.rollczi.litecommands.argument.parser.ParseResult; | ||
import dev.rollczi.litecommands.invocation.Invocation; | ||
import dev.rollczi.litecommands.suggestion.SuggestionContext; | ||
import dev.rollczi.litecommands.suggestion.SuggestionResult; | ||
import org.bukkit.Server; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.HumanEntity; | ||
import org.bukkit.entity.Player; | ||
|
||
@LiteArgument(type = Player.class) | ||
public class PlayerArgument extends AbstractViewerArgument<Player> { | ||
|
||
private final Server server; | ||
|
||
@Inject | ||
public PlayerArgument(ViewerProvider viewerProvider, TranslationManager translationManager, Server server) { | ||
super(viewerProvider, translationManager); | ||
this.server = server; | ||
} | ||
|
||
@Override | ||
public ParseResult<Player> parse(Invocation<CommandSender> invocation, String argument, Translation translation) { | ||
Player target = this.server.getPlayer(argument); | ||
|
||
if (target == null) { | ||
return ParseResult.failure(translation.argument().offlinePlayer()); | ||
} | ||
|
||
return ParseResult.success(target); | ||
} | ||
|
||
@Override | ||
public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<Player> argument, SuggestionContext context) { | ||
return this.server.getOnlinePlayers().stream() | ||
.map(HumanEntity::getName) | ||
.collect(SuggestionResult.collector()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters