-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 3.0.0-BETA-pre18. Add world and location context providers fo…
…r bukkit platform.
- Loading branch information
Showing
5 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
litecommands-bukkit/src/dev/rollczi/litecommands/bukkit/argument/LocationContext.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,34 @@ | ||
package dev.rollczi.litecommands.bukkit.argument; | ||
|
||
import dev.rollczi.litecommands.bukkit.LiteBukkitMessages; | ||
import dev.rollczi.litecommands.context.ContextProvider; | ||
import dev.rollczi.litecommands.context.ContextResult; | ||
import dev.rollczi.litecommands.invocation.Invocation; | ||
import dev.rollczi.litecommands.message.MessageRegistry; | ||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public class LocationContext implements ContextProvider<CommandSender, Location> { | ||
|
||
private final MessageRegistry messageRegistry; | ||
|
||
public LocationContext(MessageRegistry messageRegistry) { | ||
this.messageRegistry = messageRegistry; | ||
} | ||
|
||
@Override | ||
public ContextResult<Location> provide(Invocation<CommandSender> invocation) { | ||
CommandSender sender = invocation.sender(); | ||
|
||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
|
||
return ContextResult.ok(() -> player.getLocation()); | ||
} | ||
|
||
return ContextResult.error(messageRegistry.get(LiteBukkitMessages.LOCATION_PLAYER_ONLY, sender)); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
litecommands-bukkit/src/dev/rollczi/litecommands/bukkit/argument/WorldContext.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 dev.rollczi.litecommands.bukkit.argument; | ||
|
||
import dev.rollczi.litecommands.bukkit.LiteBukkitMessages; | ||
import dev.rollczi.litecommands.context.ContextProvider; | ||
import dev.rollczi.litecommands.context.ContextResult; | ||
import dev.rollczi.litecommands.invocation.Invocation; | ||
import dev.rollczi.litecommands.message.MessageRegistry; | ||
import org.bukkit.World; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public class WorldContext implements ContextProvider<CommandSender, World> { | ||
|
||
private final MessageRegistry messageRegistry; | ||
|
||
public WorldContext(MessageRegistry messageRegistry) { | ||
this.messageRegistry = messageRegistry; | ||
} | ||
|
||
@Override | ||
public ContextResult<World> provide(Invocation<CommandSender> invocation) { | ||
CommandSender sender = invocation.sender(); | ||
|
||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
|
||
return ContextResult.ok(() -> player.getWorld()); | ||
} | ||
|
||
return ContextResult.error(messageRegistry.get(LiteBukkitMessages.WORLD_PLAYER_ONLY, sender)); | ||
} | ||
|
||
} |
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