32 lines
1.1 KiB
Java
32 lines
1.1 KiB
Java
package games.dmg.spigotquestboard;
|
|
|
|
import java.io.IOException;
|
|
import java.time.Instant;
|
|
import java.util.Objects;
|
|
import java.util.UUID;
|
|
import org.bukkit.entity.Player;
|
|
|
|
final class QuestCancellationController implements QuestCancellationGateway {
|
|
private final QuestService quests;
|
|
|
|
QuestCancellationController(QuestService quests) {
|
|
this.quests = Objects.requireNonNull(quests, "quests");
|
|
}
|
|
|
|
@Override
|
|
public QuestClaim cancel(Player player, String questId, Instant cancelledAt) throws IOException {
|
|
Objects.requireNonNull(player, "player");
|
|
final UUID id;
|
|
try {
|
|
id = UUID.fromString(Objects.requireNonNull(questId, "questId"));
|
|
} catch (IllegalArgumentException exception) {
|
|
throw new IllegalArgumentException("Quest identifier must be a valid UUID.", exception);
|
|
}
|
|
QuestClaim claim = quests.cancel(id, player.getUniqueId(), cancelledAt);
|
|
player.sendMessage(
|
|
"Quest " + id + " cancelled. Your exact escrowed reward is ready to claim at a quest board."
|
|
);
|
|
return claim;
|
|
}
|
|
}
|