2018-01-12 10:02:32 +01:00
|
|
|
/*
|
2018-10-28 09:10:56 +01:00
|
|
|
* This file is part of Player Analytics (Plan).
|
|
|
|
*
|
|
|
|
* Plan is free software: you can redistribute it and/or modify
|
2018-11-11 19:55:11 +01:00
|
|
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
2018-10-28 09:10:56 +01:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Plan is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-11-11 19:55:11 +01:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-10-28 09:10:56 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
2018-01-12 10:02:32 +01:00
|
|
|
*/
|
2020-03-01 20:24:48 +01:00
|
|
|
package com.djrapitops.plan.delivery.webserver.resolver;
|
2018-01-12 10:02:32 +01:00
|
|
|
|
2020-02-16 17:18:14 +01:00
|
|
|
import com.djrapitops.plan.delivery.web.resolver.Resolver;
|
|
|
|
import com.djrapitops.plan.delivery.web.resolver.Response;
|
|
|
|
import com.djrapitops.plan.delivery.web.resolver.request.Request;
|
2020-03-01 20:24:48 +01:00
|
|
|
import com.djrapitops.plan.delivery.webserver.ResponseFactory;
|
2018-01-12 10:02:32 +01:00
|
|
|
|
2018-08-27 16:18:17 +02:00
|
|
|
import javax.inject.Inject;
|
2018-08-28 09:51:38 +02:00
|
|
|
import javax.inject.Singleton;
|
2020-02-13 22:28:13 +01:00
|
|
|
import java.util.Optional;
|
2018-01-12 10:02:32 +01:00
|
|
|
|
|
|
|
/**
|
2019-12-05 18:42:20 +01:00
|
|
|
* Resolves /players URL.
|
2018-01-12 10:02:32 +01:00
|
|
|
*
|
2021-02-13 14:16:03 +01:00
|
|
|
* @author AuroraLS3
|
2018-01-12 10:02:32 +01:00
|
|
|
*/
|
2018-08-28 09:51:38 +02:00
|
|
|
@Singleton
|
2020-02-13 22:28:13 +01:00
|
|
|
public class PlayersPageResolver implements Resolver {
|
2018-08-27 16:18:17 +02:00
|
|
|
|
|
|
|
private final ResponseFactory responseFactory;
|
|
|
|
|
|
|
|
@Inject
|
2019-12-05 18:42:20 +01:00
|
|
|
public PlayersPageResolver(
|
2019-02-22 09:35:06 +01:00
|
|
|
ResponseFactory responseFactory
|
|
|
|
) {
|
2018-08-27 16:18:17 +02:00
|
|
|
this.responseFactory = responseFactory;
|
|
|
|
}
|
2018-01-12 10:02:32 +01:00
|
|
|
|
|
|
|
@Override
|
2020-02-16 17:18:14 +01:00
|
|
|
public boolean canAccess(Request request) {
|
|
|
|
return request.getUser().map(user -> user.hasPermission("page.players")).orElse(false);
|
2018-01-12 10:02:32 +01:00
|
|
|
}
|
2018-01-14 20:31:31 +01:00
|
|
|
|
|
|
|
@Override
|
2020-02-16 17:18:14 +01:00
|
|
|
public Optional<Response> resolve(Request request) {
|
2020-03-28 12:00:34 +01:00
|
|
|
// Redirect /players/ to /players
|
|
|
|
if (request.getPath().getPart(1).isPresent()) return Optional.of(responseFactory.redirectResponse("/players"));
|
2023-01-22 09:18:14 +01:00
|
|
|
return Optional.of(responseFactory.playersPageResponse(request));
|
2018-01-14 20:31:31 +01:00
|
|
|
}
|
2018-06-12 20:28:40 +02:00
|
|
|
}
|