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());
}
}
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);
}
}
});
}
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;
}
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);
}
});
}
Aggregations