Search in sources :

Example 1 with SpawnApply

use of pl.themolka.arcade.spawn.SpawnApply in project Arcade2 by ShootGame.

the class TeamApplyListeners method playerRespawn.

// This is a special listener where we manually set player's
// respawn location by looping all apply contents.
@Handler(priority = Priority.LOWEST)
public void playerRespawn(PlayerRespawnEvent event) {
    GamePlayer player = event.getGamePlayer();
    Team team = this.game.getTeam(player);
    if (this.shouldApplyTo(team)) {
        player.getPlayer().clearInventory(true);
        Location spawn = this.fetchSpawn(team, MatchApplyContext.EventType.PLAYER_RESPAWN, player);
        if (spawn != null) {
            event.setRespawnPosition(spawn);
        }
        // The player must be spawned to be able to be meta attachable.
        this.game.getServer().getScheduler().runTaskLater(this.game.getPlugin(), new Runnable() {

            @Override
            public void run() {
                if (!player.isOnline()) {
                    return;
                }
                for (PlayerApplicable content : team.getApplyContext().getAllContent(MatchApplyContext.EventType.PLAYER_RESPAWN)) {
                    if (!(content instanceof SpawnApply)) {
                        content.apply(player);
                    }
                }
            }
        }, Time.ZERO.toTicks());
    }
}
Also used : PlayerApplicable(pl.themolka.arcade.game.PlayerApplicable) GamePlayer(pl.themolka.arcade.game.GamePlayer) SpawnApply(pl.themolka.arcade.spawn.SpawnApply) Location(org.bukkit.Location) Handler(net.engio.mbassy.listener.Handler)

Example 2 with SpawnApply

use of pl.themolka.arcade.spawn.SpawnApply in project Arcade2 by ShootGame.

the class PortalParser method parseDestination.

protected SpawnApply parseDestination(Node node, String name, String value) throws ParserException {
    Spawn destination = (Spawn) this.destinationParser.parse(node.property("destination")).orFail().get();
    boolean smooth = this.smoothParser.parse(node.property("smooth")).orDefault(false);
    Direction yaw = this.yawDirectionParser.parse(node.property("yaw")).orDefault(Direction.ENTITY);
    Direction pitch = this.pitchDirectionParser.parse(node.property("pitch")).orDefault(Direction.ENTITY);
    return new SpawnApply(destination, new SpawnApply.AgentFactory() {

        @Override
        public SpawnAgent createAgent(Spawn spawn, GamePlayer player, Player bukkit) {
            if (smooth) {
                return SmoothSpawnAgent.create(spawn, player.getBukkit(), yaw, pitch);
            } else {
                return SpawnAgent.create(spawn, player.getBukkit(), yaw, pitch);
            }
        }
    });
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) Player(org.bukkit.entity.Player) SpawnApply(pl.themolka.arcade.spawn.SpawnApply) GamePlayer(pl.themolka.arcade.game.GamePlayer) SmoothSpawnAgent(pl.themolka.arcade.spawn.SmoothSpawnAgent) SpawnAgent(pl.themolka.arcade.spawn.SpawnAgent) Spawn(pl.themolka.arcade.spawn.Spawn) Direction(pl.themolka.arcade.spawn.Direction)

Example 3 with SpawnApply

use of pl.themolka.arcade.spawn.SpawnApply in project Arcade2 by ShootGame.

the class Portal method teleport.

public Location teleport(GamePlayer player) {
    if (player == null || !player.isOnline()) {
        return null;
    }
    PlayerPortalEvent event = new PlayerPortalEvent(this.getPlugin(), this, player, this.destination, TELEPORT_SOUND);
    this.getPlugin().getEventBus().publish(event);
    SpawnApply destination = event.getDestination();
    if (destination == null || event.isCanceled()) {
        return null;
    }
    Location location = destination.spawn(player);
    if (location != null) {
        this.playSound(location, event.getSound(), player);
        if (this.hasKit()) {
            this.kit.apply(player);
        }
    }
    return location;
}
Also used : SpawnApply(pl.themolka.arcade.spawn.SpawnApply) Location(org.bukkit.Location)

Example 4 with SpawnApply

use of pl.themolka.arcade.spawn.SpawnApply in project Arcade2 by ShootGame.

the class PortalParser method parseNode.

@Override
protected ParserResult<Portal.Config> parseNode(Node node, String name, String value) throws ParserException {
    SpawnApply destination = this.parseDestination(node, name, value);
    Ref<Filter> filter = this.filterParser.parse(node.property("filter")).orDefault(Ref.empty());
    String id = this.parseOptionalId(node);
    Ref<Kit> kit = this.kitParser.parse(node.property("kit")).orDefault(Ref.empty());
    AbstractRegion.Config<?> region = this.regionParser.parseWithDefinition(node, name, value).orFail();
    return ParserResult.fine(node, name, value, new Portal.Config() {

        public SpawnApply destination() {
            return destination;
        }

        public Ref<Filter> filter() {
            return filter;
        }

        public String id() {
            return id;
        }

        public Ref<Kit> kit() {
            return kit;
        }

        public Ref<AbstractRegion.Config<?>> region() {
            return Ref.ofProvided(region);
        }
    });
}
Also used : Ref(pl.themolka.arcade.config.Ref) Filter(pl.themolka.arcade.filter.Filter) SpawnApply(pl.themolka.arcade.spawn.SpawnApply) Kit(pl.themolka.arcade.kit.Kit) AbstractRegion(pl.themolka.arcade.region.AbstractRegion)

Aggregations

SpawnApply (pl.themolka.arcade.spawn.SpawnApply)4 Location (org.bukkit.Location)2 GamePlayer (pl.themolka.arcade.game.GamePlayer)2 Handler (net.engio.mbassy.listener.Handler)1 Player (org.bukkit.entity.Player)1 Ref (pl.themolka.arcade.config.Ref)1 Filter (pl.themolka.arcade.filter.Filter)1 PlayerApplicable (pl.themolka.arcade.game.PlayerApplicable)1 Kit (pl.themolka.arcade.kit.Kit)1 AbstractRegion (pl.themolka.arcade.region.AbstractRegion)1 Direction (pl.themolka.arcade.spawn.Direction)1 SmoothSpawnAgent (pl.themolka.arcade.spawn.SmoothSpawnAgent)1 Spawn (pl.themolka.arcade.spawn.Spawn)1 SpawnAgent (pl.themolka.arcade.spawn.SpawnAgent)1