From 3d07e83d026a8b197cff9a95c9ca57854bdf5f8b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 20 May 2024 14:51:11 +0200 Subject: [PATCH] Update Permission and Region and PermissionSystem and RegionSystem --- .../src/de/steamwar/bausystem/Permission.java | 43 +++++++++++++++++++ .../permission/PermissionSystem.java | 39 +++++++++++++++++ .../de/steamwar/bausystem/region/Region.java | 4 +- .../bausystem/region/RegionSystem.java | 3 ++ 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 BauSystem_PluginBase/src/de/steamwar/bausystem/Permission.java create mode 100644 BauSystem_PluginBase/src/de/steamwar/bausystem/permission/PermissionSystem.java diff --git a/BauSystem_PluginBase/src/de/steamwar/bausystem/Permission.java b/BauSystem_PluginBase/src/de/steamwar/bausystem/Permission.java new file mode 100644 index 00000000..6fb3a82a --- /dev/null +++ b/BauSystem_PluginBase/src/de/steamwar/bausystem/Permission.java @@ -0,0 +1,43 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem; + +import de.steamwar.bausystem.permission.PermissionSystem; +import de.steamwar.providers.BauServerInfo; +import de.steamwar.sql.BauweltMember; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.entity.Player; + +public interface Permission { + + Permission OWNER = PermissionSystem.impl::isOwner; + Permission SUPERVISOR = PermissionSystem.impl::isSupervisor; + Permission BUILD = PermissionSystem.impl::isBuilder; + Permission SPECTATOR = PermissionSystem.impl::isSpectator; + Permission MEMBER = PermissionSystem.impl::isMember; + + boolean hasPermission(SteamwarUser steamwarUser, BauweltMember bauweltMember); + + default boolean hasPermission(Player player) { + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); + BauweltMember bauweltMember = BauweltMember.getBauMember(BauServerInfo.getOwnerId(), steamwarUser.getId()); + return hasPermission(steamwarUser, bauweltMember); + } +} diff --git a/BauSystem_PluginBase/src/de/steamwar/bausystem/permission/PermissionSystem.java b/BauSystem_PluginBase/src/de/steamwar/bausystem/permission/PermissionSystem.java new file mode 100644 index 00000000..e9fde79b --- /dev/null +++ b/BauSystem_PluginBase/src/de/steamwar/bausystem/permission/PermissionSystem.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.permission; + +import de.steamwar.ImplementationProvider; +import de.steamwar.sql.BauweltMember; +import de.steamwar.sql.SteamwarUser; + +public interface PermissionSystem { + + PermissionSystem impl = ImplementationProvider.getImpl("de.steamwar.bausystem.permission.PermissionSystemImpl"); + + boolean isOwner(SteamwarUser steamwarUser, BauweltMember bauweltMember); + + boolean isSupervisor(SteamwarUser steamwarUser, BauweltMember bauweltMember); + + boolean isBuilder(SteamwarUser steamwarUser, BauweltMember bauweltMember); + + boolean isSpectator(SteamwarUser steamwarUser, BauweltMember bauweltMember); + + boolean isMember(SteamwarUser steamwarUser, BauweltMember bauweltMember); +} diff --git a/BauSystem_PluginBase/src/de/steamwar/bausystem/region/Region.java b/BauSystem_PluginBase/src/de/steamwar/bausystem/region/Region.java index 0d3f80e9..b4c7290b 100644 --- a/BauSystem_PluginBase/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_PluginBase/src/de/steamwar/bausystem/region/Region.java @@ -30,10 +30,8 @@ import java.util.Optional; public interface Region { - RegionSystem REGION_SYSTEM = null; // TODO: Add Loading of Implementation - static Region get(Location location) { - return REGION_SYSTEM.get(location); + return RegionSystem.impl.get(location); } enum HasFlagResult { diff --git a/BauSystem_PluginBase/src/de/steamwar/bausystem/region/RegionSystem.java b/BauSystem_PluginBase/src/de/steamwar/bausystem/region/RegionSystem.java index 105d41ba..5cc401c6 100644 --- a/BauSystem_PluginBase/src/de/steamwar/bausystem/region/RegionSystem.java +++ b/BauSystem_PluginBase/src/de/steamwar/bausystem/region/RegionSystem.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.region; +import de.steamwar.ImplementationProvider; import org.bukkit.Location; import java.util.Optional; @@ -26,6 +27,8 @@ import java.util.stream.Stream; public interface RegionSystem { + RegionSystem impl = ImplementationProvider.getImpl("de.steamwar.bausystem.region.RegionSystemImpl"); + void load(); void save();