-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow admins to change a player's selected block type via command
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
spigot/src/main/java/io/tofpu/speedbridge2/command/parser/BridgePlayerParser.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,33 @@ | ||
package io.tofpu.speedbridge2.command.parser; | ||
|
||
import io.tofpu.dynamicclass.meta.AutoRegister; | ||
import io.tofpu.speedbridge2.model.common.util.BridgeUtil; | ||
import io.tofpu.speedbridge2.model.player.PlayerService; | ||
import io.tofpu.speedbridge2.model.player.object.BridgePlayer; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import revxrsal.commands.exception.CommandErrorException; | ||
import revxrsal.commands.process.ValueResolver; | ||
|
||
import static io.tofpu.speedbridge2.model.common.Message.INSTANCE; | ||
|
||
@AutoRegister | ||
public class BridgePlayerParser extends AbstractLampParser<BridgePlayer> { | ||
private final PlayerService playerService; | ||
|
||
public BridgePlayerParser(PlayerService playerService, LampParseRegistry registry) { | ||
super(BridgePlayer.class, registry); | ||
this.playerService = playerService; | ||
} | ||
|
||
@Override | ||
BridgePlayer parse(ValueResolver.ValueResolverContext context) { | ||
final String input = context.pop(); | ||
Player player = Bukkit.getPlayer(input); | ||
BridgePlayer bridgePlayer = player == null ? null : playerService.getIfPresent(player.getUniqueId()); | ||
if (bridgePlayer == null) { | ||
throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(String.format(INSTANCE.mustBeOnline, input))); | ||
} | ||
return bridgePlayer; | ||
} | ||
} |
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
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