Search in sources :

Example 6 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class JungleRaidInstance method add.

@Override
public Clause<Player, ZoneStatus> add(Player player) {
    if (state != JungleRaidState.LOBBY) {
        return new Clause<>(player, ZoneStatus.NO_REJOIN);
    }
    player.setLocation(lobbySpawnLocation);
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (optService.isPresent()) {
        PlayerStateService service = optService.get();
        try {
            service.storeInventory(player);
            service.releaseInventory(player);
            giveBaseEquipment(player, JungleRaidClass.BALANCED);
        } catch (InventoryStorageStateException e) {
            e.printStackTrace();
            return new Clause<>(player, ZoneStatus.ERROR);
        }
    }
    participants.add(player);
    return new Clause<>(player, ZoneStatus.ADDED);
}
Also used : PlayerStateService(com.skelril.skree.service.PlayerStateService) InventoryStorageStateException(com.skelril.skree.service.internal.playerstate.InventoryStorageStateException) Clause(com.skelril.nitro.Clause)

Example 7 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class JungleRaidInstance method tryInventoryRestore.

public void tryInventoryRestore(Player player) {
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (optService.isPresent()) {
        PlayerStateService service = optService.get();
        service.loadInventoryIfStored(player);
    }
}
Also used : PlayerStateService(com.skelril.skree.service.PlayerStateService)

Example 8 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class SkyWarsInstance method remove.

@Override
public Clause<Player, ZoneStatus> remove(Player player) {
    player.offer(Keys.FALL_DISTANCE, 0F);
    playerLost(player);
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (optService.isPresent()) {
        PlayerStateService service = optService.get();
        service.loadInventoryIfStored(player);
    }
    return super.remove(player);
}
Also used : PlayerStateService(com.skelril.skree.service.PlayerStateService)

Example 9 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class TempleOfFateInstance method tryInventoryRestore.

public void tryInventoryRestore(Player player) {
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (optService.isPresent()) {
        PlayerStateService service = optService.get();
        service.loadInventoryIfStored(player);
    }
}
Also used : PlayerStateService(com.skelril.skree.service.PlayerStateService)

Example 10 with PlayerStateService

use of com.skelril.skree.service.PlayerStateService in project Skree by Skelril.

the class GameModeCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The player state service is not currently running."));
        return CommandResult.empty();
    }
    PlayerStateService service = optService.get();
    GameMode mode = args.<GameMode>getOne("mode").get();
    Player target = args.<Player>getOne("target").get();
    if (service.hasInventoryStored(target) && !args.hasAny("f")) {
        src.sendMessage(Text.of(TextColors.RED, "Player has an omni-state stored, action denied."));
        src.sendMessage(Text.of(TextColors.RED, "This can be overwritten using -f."));
        return CommandResult.empty();
    }
    service.save(target, target.get(Keys.GAME_MODE).get().getId());
    target.offer(Keys.FALL_DISTANCE, 0F);
    target.offer(Keys.GAME_MODE, mode);
    service.load(target, mode.getId());
    target.sendMessage(Text.of(TextColors.YELLOW, "Changed game mode to " + mode.getName() + '.'));
    return CommandResult.success();
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Player(org.spongepowered.api.entity.living.player.Player) PlayerStateService(com.skelril.skree.service.PlayerStateService)

Aggregations

PlayerStateService (com.skelril.skree.service.PlayerStateService)12 InventoryStorageStateException (com.skelril.skree.service.internal.playerstate.InventoryStorageStateException)5 Clause (com.skelril.nitro.Clause)3 BigDecimal (java.math.BigDecimal)2 Player (org.spongepowered.api.entity.living.player.Player)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 MarketService (com.skelril.skree.service.MarketService)1 GameMode (org.spongepowered.api.entity.living.player.gamemode.GameMode)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 MessageChannel (org.spongepowered.api.text.channel.MessageChannel)1