use of com.easterlyn.util.Request in project Easterlyn by Easterlyn.
the class SpectateCommand method spectateTPA.
@CommandAlias("spectate|spec|spectpa")
@Subcommand("request")
@Description("{@@spectate.request.description}")
@CommandCompletion("@player")
@Syntax("/spectpa <player>")
@CommandPermission("easterlyn.command.spectpa")
public void spectateTPA(@Flags(CoreContexts.SELF) User user, @Flags(CoreContexts.ONLINE) User target) {
Player player = user.getPlayer();
Player targetPlayer = target.getPlayer();
if (player == null || targetPlayer == null) {
core.getLocaleManager().sendMessage(user.getPlayer(), "sink.module.tprequest.error.offline");
return;
}
if (player.getGameMode() != GameMode.SPECTATOR) {
core.getLocaleManager().sendMessage(player, "spectate.not_spectator");
return;
}
if (target.setPendingRequest(new Request() {
@Override
public void accept() {
Player issuer = user.getPlayer();
Player recipient = target.getPlayer();
if (issuer == null || recipient == null) {
core.getLocaleManager().sendMessage(recipient, "sink.module.tprequest.error.offline");
return;
}
if (issuer.getGameMode() != GameMode.SPECTATOR) {
core.getLocaleManager().sendMessage(user.getPlayer(), "spectate.request.not_spectator", "{value}", issuer.getName());
return;
}
user.getStorage().set(EasterlynSpectators.USER_SPECTPA, true);
if (issuer.teleport(recipient.getLocation().add(0, 0.1, 0), PlayerTeleportEvent.TeleportCause.SPECTATE)) {
core.getLocaleManager().sendMessage(recipient, "sink.module.tprequest.common.accept");
core.getLocaleManager().sendMessage(issuer, "sink.module.tprequest.common.accepted", "{target}", recipient.getName());
}
user.getStorage().set(EasterlynSpectators.USER_SPECTPA, null);
}
@Override
public void decline() {
core.getLocaleManager().sendMessage(targetPlayer, "sink.module.tprequest.common.decline");
core.getLocaleManager().sendMessage(player, "sink.module.tprequest.common.declined", "{target}", targetPlayer.getName());
// TODO same anti-spam ignore?
}
})) {
String message = core.getLocaleManager().getValue("spectate.request.request", core.getLocaleManager().getLocale(targetPlayer), "{value}", player.getName());
if (message != null) {
target.sendMessage(player.getUniqueId(), message);
}
} else {
core.getLocaleManager().sendMessage(player, "sink.module.tprequest.error.popular", "{value}", targetPlayer.getName());
}
}
Aggregations