From fca57f8110fa53e67a1ec915f4d5cc1fdf1ee5a1 Mon Sep 17 00:00:00 2001 From: Karol Dronia <80169196+eripe14@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:44:09 +0200 Subject: [PATCH 01/21] Add possibility to manage warp permissions --- .../implementation/PluginConfiguration.java | 12 ++-- .../core/feature/warp/WarpInventory.java | 9 ++- .../warp/WarpPermissionController.java | 69 +++++++++++++++++++ .../core/translation/Translation.java | 4 +- .../implementation/ENTranslation.java | 7 +- .../implementation/PLTranslation.java | 7 +- 6 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java index 24db4bc7c..8a50cf4bc 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java @@ -6,15 +6,13 @@ import com.eternalcode.core.feature.afk.AfkSettings; import com.eternalcode.core.feature.automessage.AutoMessageSettings; import com.eternalcode.core.feature.chat.ChatSettings; +import com.eternalcode.core.feature.helpop.HelpOpSettings; import com.eternalcode.core.feature.jail.JailSettings; import com.eternalcode.core.feature.randomteleport.RandomTeleportSettings; import com.eternalcode.core.feature.randomteleport.RandomTeleportType; -import com.eternalcode.core.feature.helpop.HelpOpSettings; import com.eternalcode.core.feature.spawn.SpawnSettings; -import com.eternalcode.core.injector.annotations.component.ConfigurationFile; import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings; -import java.util.LinkedHashMap; -import java.util.Set; +import com.eternalcode.core.injector.annotations.component.ConfigurationFile; import net.dzikoysk.cdn.entity.Contextual; import net.dzikoysk.cdn.entity.Description; import net.dzikoysk.cdn.entity.Exclude; @@ -25,7 +23,9 @@ import java.io.File; import java.time.Duration; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; @ConfigurationFile public class PluginConfiguration implements ReloadableConfig { @@ -396,6 +396,10 @@ public static class Warp { @Description("# Texture of the item (only for PLAYER_HEAD material)") public String itemTexture = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk4ODVlODIzZmYxNTkyNjdjYmU4MDkwOTNlMzNhNDc2ZTI3NDliNjU5OGNhNGEyYTgxZWU2OTczODAzZmI2NiJ9fX0="; + @Description("# Permissions assigned to warp") + public Map> warpPermissions = Map.of( + "default_warp", Set.of("eternalcore.warp.default") + ); } @Description({ " ", "# Butcher" }) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java index 03f1b97eb..df50d1fc9 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java @@ -15,15 +15,16 @@ import dev.triumphteam.gui.builder.item.ItemBuilder; import dev.triumphteam.gui.guis.Gui; import dev.triumphteam.gui.guis.GuiItem; -import java.util.Collections; -import java.util.List; -import java.util.Optional; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.entity.Player; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + @Service public class WarpInventory { @@ -198,13 +199,11 @@ public void openInventory(Player player, Language language) { } public void addWarp(Warp warp) { - if (!this.warpManager.warpExists(warp.getName())) { return; } for (Language language : this.translationManager.getAvailableLanguages()) { - AbstractTranslation translation = (AbstractTranslation) this.translationManager.getMessages(language); Translation.WarpSection.WarpInventorySection warpSection = translation.warp().warpInventory(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java new file mode 100644 index 000000000..1fcb79ddf --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java @@ -0,0 +1,69 @@ +package com.eternalcode.core.feature.warp; + +import com.eternalcode.annotations.scan.feature.FeatureDocs; +import com.eternalcode.core.configuration.implementation.PluginConfiguration; +import com.eternalcode.core.feature.warp.event.PreWarpTeleportEvent; +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.injector.annotations.component.Controller; +import com.eternalcode.core.notice.NoticeService; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; + +@FeatureDocs( + description = "Check if a player has permission to use a specific warp", + name = "Warp permission" +) +@Controller +public class WarpPermissionController implements Listener { + + private final NoticeService noticeService; + private final PluginConfiguration pluginConfiguration; + + @Inject + public WarpPermissionController(NoticeService noticeService, PluginConfiguration pluginConfiguration) { + this.noticeService = noticeService; + this.pluginConfiguration = pluginConfiguration; + } + + @EventHandler + void onWarpPreTeleportation(PreWarpTeleportEvent event) { + Player player = event.getPlayer(); + UUID uniqueId = player.getUniqueId(); + Warp warp = event.getWarp(); + + this.checkWarpPermission(event, warp, player, uniqueId); + } + + private void checkWarpPermission(PreWarpTeleportEvent event, Warp warp, Player player, UUID uniqueId) { + Map> warpPermissions = this.pluginConfiguration.warp.warpPermissions; + + if (!warpPermissions.containsKey(warp.getName())) { + return; + } + + Set permissions = warpPermissions.get(warp.getName()); + Optional isPlayerAllowedToUseWarp = permissions + .stream() + .filter(player::hasPermission) + .findAny(); + + if (isPlayerAllowedToUseWarp.isPresent()) { + return; + } + + event.setCancelled(true); + + this.noticeService.create() + .player(uniqueId) + .placeholder("{WARP}", warp.getName()) + .notice(translation -> translation.warp().noPermission()) + .send(); + } + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java index d9333c3a3..dd7fd988e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java @@ -1,11 +1,12 @@ package com.eternalcode.core.translation; import com.eternalcode.core.configuration.contextual.ConfigItem; -import com.eternalcode.core.feature.warp.WarpInventoryItem; import com.eternalcode.core.feature.language.Language; +import com.eternalcode.core.feature.warp.WarpInventoryItem; import com.eternalcode.multification.notice.Notice; import org.bukkit.Material; import org.bukkit.event.entity.EntityDamageEvent; + import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -146,6 +147,7 @@ interface WarpSection { Notice itemAdded(); Notice noWarps(); Notice itemLimit(); + Notice noPermission(); WarpInventorySection warpInventory(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java index 31b67724b..61bc37b49 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java @@ -1,12 +1,11 @@ package com.eternalcode.core.translation.implementation; import com.eternalcode.core.configuration.contextual.ConfigItem; -import com.eternalcode.core.feature.warp.WarpInventoryItem; import com.eternalcode.core.feature.language.Language; +import com.eternalcode.core.feature.warp.WarpInventoryItem; import com.eternalcode.core.translation.AbstractTranslation; import com.eternalcode.multification.bukkit.notice.BukkitNotice; import com.eternalcode.multification.notice.Notice; -import java.util.HashMap; import lombok.Getter; import lombok.experimental.Accessors; import net.dzikoysk.cdn.entity.Contextual; @@ -14,9 +13,11 @@ import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.event.entity.EntityDamageEvent; + import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -370,6 +371,7 @@ public static class ENWarpSection implements WarpSection { public Notice itemAdded = Notice.chat("Warp has been added to GUI!"); public Notice noWarps = Notice.chat("There are no warps!"); public Notice itemLimit = Notice.chat("You have reached the limit of warps! Your limit is {LIMIT}."); + public Notice noPermission = Notice.chat("You don't have permission to use this warp ({WARP})!"); @Description({" ", "# {WARPS} - List of warps (separated by commas)"}) public Notice available = Notice.chat("Available warps: {WARPS}"); @@ -382,7 +384,6 @@ public static class ENWarpSection implements WarpSection { public static class ENWarpInventory implements WarpInventorySection { public String title = "» Available warps:"; - @Description({" ", "# Warps located inside GUI inventory can be customized here. More warps will be added on creation with /setwarp command. "}) public Map items = new HashMap<>(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index 8ca7547b7..fe2c2a64f 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -1,12 +1,11 @@ package com.eternalcode.core.translation.implementation; import com.eternalcode.core.configuration.contextual.ConfigItem; -import com.eternalcode.core.feature.warp.WarpInventoryItem; import com.eternalcode.core.feature.language.Language; +import com.eternalcode.core.feature.warp.WarpInventoryItem; import com.eternalcode.core.translation.AbstractTranslation; import com.eternalcode.multification.bukkit.notice.BukkitNotice; import com.eternalcode.multification.notice.Notice; -import java.util.HashMap; import lombok.Getter; import lombok.experimental.Accessors; import net.dzikoysk.cdn.entity.Contextual; @@ -14,9 +13,11 @@ import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.event.entity.EntityDamageEvent; + import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -373,6 +374,7 @@ public static class PLWarpSection implements WarpSection { public Notice itemAdded = Notice.chat("Dodano warp do GUI!"); public Notice noWarps = Notice.chat("Błąd: Nie ma dostępnych warpów!"); public Notice itemLimit = Notice.chat("Błąd: Osiągnąłeś limit warpów w GUI! Limit to: {LIMIT}!"); + public Notice noPermission = Notice.chat("Błąd: Nie masz uprawnień do skorzystania z tego warpa ({WARP})!"); @Description({" ", "# {WARPS} - Lista dostępnych warpów"}) public Notice available = Notice.chat("Dostepne warpy: {WARPS}!"); @@ -395,7 +397,6 @@ public void setItems(Map items) { this.items = items; } - public PLBorderSection border = new PLBorderSection(); public PLDecorationItemsSection decorationItems = new PLDecorationItemsSection(); From 65e75646bbc56bfdb3a9061471e1da13dc06bef1 Mon Sep 17 00:00:00 2001 From: Karol Dronia <80169196+eripe14@users.noreply.github.com> Date: Tue, 8 Oct 2024 18:46:43 +0200 Subject: [PATCH 02/21] Change warp permission feature --- .../eternalcode/core/feature/warp/Warp.java | 6 ++ .../core/feature/warp/WarpService.java | 6 ++ .../configuration/ConfigurationManager.java | 9 +- .../LocationsConfiguration.java | 3 +- .../implementation/PluginConfiguration.java | 5 -- .../implementation/WarpsConfiguration.java | 23 +++++ .../core/feature/warp/WarpConfigEntry.java | 20 +++++ .../feature/warp/WarpConfigRepository.java | 89 ++++++++++++++++--- .../core/feature/warp/WarpImpl.java | 16 +++- .../core/feature/warp/WarpInventory.java | 1 - .../warp/WarpPermissionController.java | 13 +-- .../core/feature/warp/WarpRepository.java | 4 + .../core/feature/warp/WarpServiceImpl.java | 49 +++++++++- .../command/AddWarpPermissionCommand.java | 50 +++++++++++ .../command/RemoveWarpPermissionCommand.java | 52 +++++++++++ .../feature/warp/command/SetWarpCommand.java | 5 +- .../core/translation/Translation.java | 4 + .../implementation/ENTranslation.java | 5 +- .../implementation/PLTranslation.java | 5 ++ 19 files changed, 324 insertions(+), 41 deletions(-) create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigEntry.java create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/AddWarpPermissionCommand.java create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/RemoveWarpPermissionCommand.java diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java index 0888c4f7f..1f4922d42 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java @@ -2,10 +2,16 @@ import org.bukkit.Location; +import java.util.List; + public interface Warp { Location getLocation(); String getName(); + List getPermissions(); + + void setPermissions(List permissions); + } diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java index 7c3da0339..dd83da95c 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java @@ -11,8 +11,14 @@ public interface WarpService { void removeWarp(String warp); + void addPermissions(String warp, String... permissions); + + void removePermission(String warp, String permission); + boolean warpExists(String name); + boolean doestWarpPermissionExist(String warp, String permission); + Optional findWarp(String name); Collection getNamesOfWarps(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/ConfigurationManager.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/ConfigurationManager.java index e0fd77dc4..b386beb86 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/ConfigurationManager.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/ConfigurationManager.java @@ -12,15 +12,16 @@ import com.eternalcode.multification.cdn.MultificationNoticeCdnComposer; import com.eternalcode.multification.notice.Notice; import com.eternalcode.multification.notice.resolver.NoticeResolverRegistry; -import java.io.File; -import java.time.Duration; -import java.util.HashSet; -import java.util.Set; import net.dzikoysk.cdn.Cdn; import net.dzikoysk.cdn.CdnFactory; import net.dzikoysk.cdn.reflect.Visibility; import org.bukkit.Material; +import java.io.File; +import java.time.Duration; +import java.util.HashSet; +import java.util.Set; + @Service public class ConfigurationManager { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java index 2f4801004..96f342780 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java @@ -1,8 +1,8 @@ package com.eternalcode.core.configuration.implementation; +import com.eternalcode.commons.bukkit.position.Position; import com.eternalcode.core.configuration.ReloadableConfig; import com.eternalcode.core.injector.annotations.component.ConfigurationFile; -import com.eternalcode.commons.bukkit.position.Position; import net.dzikoysk.cdn.entity.Description; import net.dzikoysk.cdn.entity.Exclude; import net.dzikoysk.cdn.source.Resource; @@ -22,6 +22,7 @@ public class LocationsConfiguration implements ReloadableConfig { public Position spawn = EMPTY_POSITION; @Description("# These are warp locations, for your own safety, please don't touch it.") + @Deprecated public Map warps = new HashMap<>(); @Description("# This is jail location, for your own safety, please don't touch it.") diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java index 8a50cf4bc..1ba0efe0a 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java @@ -395,11 +395,6 @@ public static class Warp { @Description("# Texture of the item (only for PLAYER_HEAD material)") public String itemTexture = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk4ODVlODIzZmYxNTkyNjdjYmU4MDkwOTNlMzNhNDc2ZTI3NDliNjU5OGNhNGEyYTgxZWU2OTczODAzZmI2NiJ9fX0="; - - @Description("# Permissions assigned to warp") - public Map> warpPermissions = Map.of( - "default_warp", Set.of("eternalcore.warp.default") - ); } @Description({ " ", "# Butcher" }) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java new file mode 100644 index 000000000..d16ba0b6e --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java @@ -0,0 +1,23 @@ +package com.eternalcode.core.configuration.implementation; + +import com.eternalcode.core.configuration.ReloadableConfig; +import com.eternalcode.core.feature.warp.WarpConfigEntry; +import com.eternalcode.core.injector.annotations.component.ConfigurationFile; +import net.dzikoysk.cdn.source.Resource; +import net.dzikoysk.cdn.source.Source; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +@ConfigurationFile +public class WarpsConfiguration implements ReloadableConfig { + + public Map warps = new HashMap<>(); + + @Override + public Resource resource(File folder) { + return Source.of(folder, "warps.yml"); + } + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigEntry.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigEntry.java new file mode 100644 index 000000000..bfa64e7da --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigEntry.java @@ -0,0 +1,20 @@ +package com.eternalcode.core.feature.warp; + +import com.eternalcode.commons.bukkit.position.Position; +import net.dzikoysk.cdn.entity.Contextual; + +import java.util.List; + +@Contextual +public class WarpConfigEntry { + public Position position; + public List permissions; + + public WarpConfigEntry() { + } + + public WarpConfigEntry(Position position, List permissions) { + this.position = position; + this.permissions = permissions; + } +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java index fccf84828..510198152 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java @@ -1,11 +1,13 @@ package com.eternalcode.core.feature.warp; -import com.eternalcode.commons.bukkit.position.Position; import com.eternalcode.commons.bukkit.position.PositionAdapter; import com.eternalcode.core.configuration.ConfigurationManager; import com.eternalcode.core.configuration.implementation.LocationsConfiguration; +import com.eternalcode.core.configuration.implementation.WarpsConfiguration; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; + +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -13,23 +15,34 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.stream.Collectors; -import panda.std.Option; @Service class WarpConfigRepository implements WarpRepository { private final LocationsConfiguration locationsConfiguration; + private final WarpsConfiguration warpsConfiguration; private final ConfigurationManager configurationManager; @Inject - WarpConfigRepository(ConfigurationManager configurationManager, LocationsConfiguration locationsConfiguration) { + WarpConfigRepository( + ConfigurationManager configurationManager, + LocationsConfiguration locationsConfiguration, + WarpsConfiguration warpsConfiguration + ) { this.locationsConfiguration = locationsConfiguration; this.configurationManager = configurationManager; + this.warpsConfiguration = warpsConfiguration; + + this.migrateWarps(); } @Override public void addWarp(Warp warp) { - this.edit(warps -> warps.put(warp.getName(), PositionAdapter.convert(warp.getLocation()))); + WarpConfigEntry warpConfigEntry = new WarpConfigEntry(PositionAdapter.convert(warp.getLocation()), warp.getPermissions()); + this.edit(warps -> warps.put( + warp.getName(), + warpConfigEntry + )); } @Override @@ -37,25 +50,77 @@ public void removeWarp(String warp) { this.edit(warps -> warps.remove(warp)); } - private void edit(Consumer> editor) { - HashMap warps = new HashMap<>(this.locationsConfiguration.warps); + @Override + public void addPermissions(String warp, String... permissions) { + this.edit(warps -> { + WarpConfigEntry warpConfigEntry = warps.get(warp); + if (warpConfigEntry == null) { + return; + } + + List newPermissions = new ArrayList<>(warpConfigEntry.permissions); + newPermissions.addAll(List.of(permissions)); + + warpConfigEntry.permissions = newPermissions; + }); + } + + @Override + public void removePermission(String warp, String permission) { + this.edit(warps -> { + WarpConfigEntry warpConfigEntry = warps.get(warp); + + if (warpConfigEntry == null) { + return; + } + List newPermissions = new ArrayList<>(warpConfigEntry.permissions); + newPermissions.remove(permission); + + warpConfigEntry.permissions = newPermissions; + }); + } + + private void edit(Consumer> editor) { + Map warps = new HashMap<>(this.warpsConfiguration.warps); editor.accept(warps); - this.locationsConfiguration.warps = warps; - this.configurationManager.save(this.locationsConfiguration); + warps.forEach((key, value) -> System.out.println(key + ": " + value)); + this.warpsConfiguration.warps.putAll(warps); + this.configurationManager.save(this.warpsConfiguration); } @Override public CompletableFuture> getWarp(String name) { - return CompletableFuture.completedFuture(Optional.of(this.locationsConfiguration.warps.get(name)) - .map(location -> new WarpImpl(name, location))); + return CompletableFuture.completedFuture(Optional.of(this.warpsConfiguration.warps.get(name)) + .map(warpConfigEntry -> new WarpImpl(name, warpConfigEntry.position, warpConfigEntry.permissions))); } @Override public CompletableFuture> getWarps() { - return CompletableFuture.completedFuture(this.locationsConfiguration.warps.entrySet().stream() - .map(entry -> new WarpImpl(entry.getKey(), entry.getValue())) + return CompletableFuture.completedFuture(this.warpsConfiguration.warps.entrySet().stream() + .map(warpConfigEntry -> { + WarpConfigEntry warpContextual = warpConfigEntry.getValue(); + return new WarpImpl(warpConfigEntry.getKey(), warpContextual.position, warpContextual.permissions); + }) .collect(Collectors.toList())); } + + private void migrateWarps() { + if (this.locationsConfiguration.warps.isEmpty()) { + return; + } + + this.edit(warps -> warps.putAll(this.locationsConfiguration.warps + .entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> + new WarpConfigEntry(entry.getValue(), new ArrayList<>())) + ) + )); + + this.locationsConfiguration.warps.clear(); + this.configurationManager.save(this.locationsConfiguration); + this.configurationManager.save(this.warpsConfiguration); + } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java index a2e8e8236..46acae415 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java @@ -4,14 +4,19 @@ import com.eternalcode.commons.bukkit.position.PositionAdapter; import org.bukkit.Location; +import java.util.Collections; +import java.util.List; + class WarpImpl implements Warp { private final String name; private final Position position; + private List permissions; - WarpImpl(String name, Position position) { + WarpImpl(String name, Position position, List permissions) { this.name = name; this.position = position; + this.permissions = permissions; } @Override @@ -23,4 +28,13 @@ public String getName() { public Location getLocation() { return PositionAdapter.convert(this.position); } + + @Override + public List getPermissions() { + return Collections.unmodifiableList(this.permissions); + } + + public void setPermissions(List permissions) { + this.permissions = permissions; + } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java index df50d1fc9..f2e9df6eb 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java @@ -81,7 +81,6 @@ private Gui createInventory(Language language) { } } - Gui gui = Gui.gui() .title(this.miniMessage.deserialize(warpSection.title())) .rows(rowsCount) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java index 1fcb79ddf..b01da97dd 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java @@ -10,9 +10,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import java.util.Map; +import java.util.List; import java.util.Optional; -import java.util.Set; import java.util.UUID; @FeatureDocs( @@ -41,19 +40,13 @@ void onWarpPreTeleportation(PreWarpTeleportEvent event) { } private void checkWarpPermission(PreWarpTeleportEvent event, Warp warp, Player player, UUID uniqueId) { - Map> warpPermissions = this.pluginConfiguration.warp.warpPermissions; - - if (!warpPermissions.containsKey(warp.getName())) { - return; - } - - Set permissions = warpPermissions.get(warp.getName()); + List permissions = warp.getPermissions(); Optional isPlayerAllowedToUseWarp = permissions .stream() .filter(player::hasPermission) .findAny(); - if (isPlayerAllowedToUseWarp.isPresent()) { + if (isPlayerAllowedToUseWarp.isPresent() || permissions.isEmpty()) { return; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java index f07b081d6..b6914269e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java @@ -10,6 +10,10 @@ interface WarpRepository { void removeWarp(String warp); + void addPermissions(String warp, String... permissions); + + void removePermission(String warp, String permission); + CompletableFuture> getWarp(String name); CompletableFuture> getWarps(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java index da85b8c3b..71f9eeb26 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java @@ -4,12 +4,15 @@ import com.eternalcode.commons.bukkit.position.PositionAdapter; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; +import org.bukkit.Location; + +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; -import org.bukkit.Location; @FeatureDocs( name = "Warp System", @@ -34,10 +37,9 @@ private WarpServiceImpl(WarpRepository warpRepository) { @Override public Warp createWarp(String name, Location location) { - Warp warp = new WarpImpl(name, PositionAdapter.convert(location)); + Warp warp = new WarpImpl(name, PositionAdapter.convert(location), new ArrayList<>()); this.warpMap.put(name, warp); - this.warpRepository.addWarp(warp); return warp; @@ -54,11 +56,52 @@ public void removeWarp(String warp) { this.warpRepository.removeWarp(remove.getName()); } + @Override + public void addPermissions(String warpName, String... permissions) { + Warp warp = this.warpMap.get(warpName); + + if (warp == null) { + return; + } + + List updatedPermissions = new ArrayList<>(warp.getPermissions()); + updatedPermissions.addAll(List.of(permissions)); + + warp.setPermissions(updatedPermissions); + this.warpRepository.addPermissions(warpName, permissions); + } + + @Override + public void removePermission(String warpName, String permission) { + Warp warp = this.warpMap.get(warpName); + + if (warp == null) { + return; + } + + List updatedPermissions = new ArrayList<>(warp.getPermissions()); + updatedPermissions.remove(permission); + + warp.setPermissions(updatedPermissions); + this.warpRepository.removePermission(warpName, permission); + } + @Override public boolean warpExists(String name) { return this.warpMap.containsKey(name); } + @Override + public boolean doestWarpPermissionExist(String warpName, String permission) { + Warp warp = this.warpMap.get(warpName); + + if (warp == null) { + return false; + } + + return warp.getPermissions().contains(permission); + } + @Override public Optional findWarp(String name) { return Optional.ofNullable(this.warpMap.get(name)); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/AddWarpPermissionCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/AddWarpPermissionCommand.java new file mode 100644 index 000000000..ecbe78185 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/AddWarpPermissionCommand.java @@ -0,0 +1,50 @@ +package com.eternalcode.core.feature.warp.command; + +import com.eternalcode.core.feature.warp.Warp; +import com.eternalcode.core.feature.warp.WarpService; +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.notice.NoticeService; +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.permission.Permission; +import org.bukkit.entity.Player; + +import java.util.UUID; + +@Command(name = "addwarp-permissions") +@Permission("eternalcore.warp.changepermissions") +public class AddWarpPermissionCommand { + + private final WarpService warpService; + private final NoticeService noticeService; + + @Inject + public AddWarpPermissionCommand(WarpService warpService, NoticeService noticeService) { + this.warpService = warpService; + this.noticeService = noticeService; + } + + @Execute + void addPermission(@Context Player player, @Arg Warp warp, @Arg String... permissions) { + UUID uniqueId = player.getUniqueId(); + + if (permissions.length == 0) { + this.noticeService.create() + .player(uniqueId) + .notice(translation -> translation.warp().noPermissionsProvided()) + .send(); + return; + } + + this.warpService.addPermissions(warp.getName(), permissions); + + this.noticeService.create() + .player(uniqueId) + .placeholder("{WARP}", warp.getName()) + .notice(translation -> translation.warp().addPermissions()) + .send(); + } + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/RemoveWarpPermissionCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/RemoveWarpPermissionCommand.java new file mode 100644 index 000000000..c71bddb5a --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/RemoveWarpPermissionCommand.java @@ -0,0 +1,52 @@ +package com.eternalcode.core.feature.warp.command; + +import com.eternalcode.core.feature.warp.Warp; +import com.eternalcode.core.feature.warp.WarpService; +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.notice.NoticeService; +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.permission.Permission; +import org.bukkit.entity.Player; + +import java.util.UUID; + +@Command(name = "removewarp-permission") +@Permission("eternalcore.warp.changepermissions") +public class RemoveWarpPermissionCommand { + + private final WarpService warpService; + private final NoticeService noticeService; + + @Inject + public RemoveWarpPermissionCommand(WarpService warpService, NoticeService noticeService) { + this.warpService = warpService; + this.noticeService = noticeService; + } + + @Execute + void removePermission(@Context Player player, @Arg Warp warp, @Arg String permission) { + UUID uniqueId = player.getUniqueId(); + + if (!warp.getPermissions().contains(permission)) { + this.noticeService.create() + .player(uniqueId) + .placeholder("{PERMISSION}", permission) + .notice(translation -> translation.warp().permissionDoesNotExist()) + .send(); + return; + } + + this.warpService.removePermission(warp.getName(), permission); + + this.noticeService.create() + .player(uniqueId) + .placeholder("{WARP}", warp.getName()) + .placeholder("{PERMISSION}", permission) + .notice(translation -> translation.warp().removePermission()) + .send(); + } + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java index e5b2ecdef..3af1c4263 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java @@ -12,9 +12,10 @@ import dev.rollczi.litecommands.annotations.context.Context; import dev.rollczi.litecommands.annotations.execute.Execute; import dev.rollczi.litecommands.annotations.permission.Permission; -import java.util.UUID; import org.bukkit.entity.Player; +import java.util.UUID; + @Command(name = "setwarp") @Permission("eternalcore.setwarp") class SetWarpCommand { @@ -62,9 +63,7 @@ private void createWarp(Player player, String warp, UUID uniqueId) { .send(); if (this.config.warp.autoAddNewWarps) { - if (this.warpService.getNamesOfWarps().size() <= MAX_WARPS_IN_GUI) { - this.warpInventory.addWarp(createdWarp); this.noticeService.create() diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java index dd7fd988e..04c5969a1 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java @@ -148,6 +148,10 @@ interface WarpSection { Notice noWarps(); Notice itemLimit(); Notice noPermission(); + Notice addPermissions(); + Notice removePermission(); + Notice permissionDoesNotExist(); + Notice noPermissionsProvided(); WarpInventorySection warpInventory(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java index 61bc37b49..cc7049cd2 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java @@ -372,7 +372,10 @@ public static class ENWarpSection implements WarpSection { public Notice noWarps = Notice.chat("There are no warps!"); public Notice itemLimit = Notice.chat("You have reached the limit of warps! Your limit is {LIMIT}."); public Notice noPermission = Notice.chat("You don't have permission to use this warp ({WARP})!"); - + public Notice addPermissions = Notice.chat("Added permissions to warp {WARP}!"); + public Notice removePermission = Notice.chat("Removed permission {PERMISSION} from warp {WARP}!"); + public Notice noPermissionsProvided = Notice.chat("No permissions provided!"); + public Notice permissionDoesNotExist = Notice.chat("Permission {PERMISSION} doesn't exist!"); @Description({" ", "# {WARPS} - List of warps (separated by commas)"}) public Notice available = Notice.chat("Available warps: {WARPS}"); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index fe2c2a64f..2430377ca 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -375,6 +375,10 @@ public static class PLWarpSection implements WarpSection { public Notice noWarps = Notice.chat("Błąd: Nie ma dostępnych warpów!"); public Notice itemLimit = Notice.chat("Błąd: Osiągnąłeś limit warpów w GUI! Limit to: {LIMIT}!"); public Notice noPermission = Notice.chat("Błąd: Nie masz uprawnień do skorzystania z tego warpa ({WARP})!"); + public Notice addPermissions = Notice.chat("Dodano uprawnienia do warpa {WARP}!"); + public Notice removePermission = Notice.chat("Usunięto uprawnienie {PERMISSION} do warpa {WARP}!"); + public Notice noPermissionsProvided = Notice.chat("Błąd: Nie podano żadnych uprawnień!"); + public Notice permissionDoesNotExist = Notice.chat("Błąd: Podane uprawnienie nie istnieje ({PERMISSION})!"); @Description({" ", "# {WARPS} - Lista dostępnych warpów"}) public Notice available = Notice.chat("Dostepne warpy: {WARPS}!"); @@ -603,6 +607,7 @@ public static class PLInventorySection implements InventorySection { @Description({ " ", "# Ta sekcja odpowiada za interakcję z graczami za pomocą komend", + "# Ta sekcja odpowiada za interakcję z graczami za pomocą komend", }) public PLPlayerSection player = new PLPlayerSection(); From 374fc8919358c1e0ef31b943a9ede3a7d948f88e Mon Sep 17 00:00:00 2001 From: Karol Dronia <80169196+eripe14@users.noreply.github.com> Date: Tue, 8 Oct 2024 18:50:26 +0200 Subject: [PATCH 03/21] Add config description --- .../configuration/implementation/LocationsConfiguration.java | 2 +- .../core/configuration/implementation/WarpsConfiguration.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java index 96f342780..aa45fa011 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java @@ -21,7 +21,7 @@ public class LocationsConfiguration implements ReloadableConfig { @Description("# This is spawn location, for your own safety, please don't touch it.") public Position spawn = EMPTY_POSITION; - @Description("# These are warp locations, for your own safety, please don't touch it.") + @Description("# Warps now are stored in warps.yml. This is deprecated.") @Deprecated public Map warps = new HashMap<>(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java index d16ba0b6e..d9fca3da7 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java @@ -3,6 +3,7 @@ import com.eternalcode.core.configuration.ReloadableConfig; import com.eternalcode.core.feature.warp.WarpConfigEntry; import com.eternalcode.core.injector.annotations.component.ConfigurationFile; +import net.dzikoysk.cdn.entity.Description; import net.dzikoysk.cdn.source.Resource; import net.dzikoysk.cdn.source.Source; @@ -13,6 +14,7 @@ @ConfigurationFile public class WarpsConfiguration implements ReloadableConfig { + @Description({"# Warps configuration", "# These are warp locations, for your own safety, please don't touch it."}) public Map warps = new HashMap<>(); @Override From f1a6ada1606de9973b6b30bf4e79dc62bb6aad36 Mon Sep 17 00:00:00 2001 From: Karol Dronia <80169196+eripe14@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:19:02 +0200 Subject: [PATCH 04/21] Resolve CitralFlo suggestion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Wojtas <80779749+CitralFlo@users.noreply.github.com> --- .../java/com/eternalcode/core/feature/warp/WarpService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java index dd83da95c..45ee1d8f7 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java @@ -17,7 +17,7 @@ public interface WarpService { boolean warpExists(String name); - boolean doestWarpPermissionExist(String warp, String permission); + boolean doesWarpPermissionExist(String warp, String permission); Optional findWarp(String name); From 2e80db7fb9159346e06c72d77f02f1a7805b9353 Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 13:57:44 +0100 Subject: [PATCH 05/21] Refactor and enhance warp permission handling --- .../eternalcode/core/feature/warp/Warp.java | 2 - .../core/feature/warp/WarpService.java | 12 +- .../implementation/WarpsConfiguration.java | 25 ---- .../feature/warp/WarpConfigRepository.java | 126 ---------------- .../core/feature/warp/WarpImpl.java | 8 +- .../core/feature/warp/WarpInventory.java | 4 +- .../warp/WarpPermissionController.java | 7 +- .../core/feature/warp/WarpRepository.java | 20 --- .../core/feature/warp/WarpServiceImpl.java | 73 +++++---- .../feature/warp/command/DelWarpCommand.java | 4 +- .../feature/warp/command/SetWarpCommand.java | 6 +- .../feature/warp/command/WarpArgument.java | 2 +- .../feature/warp/command/WarpCommand.java | 4 +- .../WarpAddPermissionCommand.java} | 8 +- .../WarpRemovePermissionCommand.java} | 25 ++-- .../WarpPermissionMultiArgumentResolver.java | 138 ++++++++++++++++++ .../WarpPermissionMultipleResolverEntry.java | 6 + .../feature/warp/data/WarpDataConfig.java | 26 ++++ .../WarpDataConfigRepresenter.java} | 11 +- .../warp/data/WarpDataDataRepositoryImpl.java | 129 ++++++++++++++++ .../feature/warp/data/WarpDataRepository.java | 21 +++ .../core/translation/Translation.java | 3 + .../implementation/ENTranslation.java | 3 + .../implementation/PLTranslation.java | 19 ++- 24 files changed, 433 insertions(+), 249 deletions(-) delete mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java delete mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java delete mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/{AddWarpPermissionCommand.java => permission/WarpAddPermissionCommand.java} (88%) rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/{RemoveWarpPermissionCommand.java => permission/WarpRemovePermissionCommand.java} (68%) create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultipleResolverEntry.java create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfig.java rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/{WarpConfigEntry.java => data/WarpDataConfigRepresenter.java} (57%) create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java create mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java index 1f4922d42..c1cc16f45 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java @@ -12,6 +12,4 @@ public interface Warp { List getPermissions(); - void setPermissions(List permissions); - } diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java index 45ee1d8f7..b5e73bed0 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java @@ -7,21 +7,21 @@ public interface WarpService { - Warp createWarp(String name, Location location); + Warp create(String name, Location location); - void removeWarp(String warp); + void delete(String warp); void addPermissions(String warp, String... permissions); void removePermission(String warp, String permission); - boolean warpExists(String name); + boolean exists(String name); - boolean doesWarpPermissionExist(String warp, String permission); + boolean hasPermission(String warp, String permission); Optional findWarp(String name); - Collection getNamesOfWarps(); + Collection getAllNames(); - boolean hasWarps(); + boolean isEmpty(); } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java deleted file mode 100644 index d9fca3da7..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.eternalcode.core.configuration.implementation; - -import com.eternalcode.core.configuration.ReloadableConfig; -import com.eternalcode.core.feature.warp.WarpConfigEntry; -import com.eternalcode.core.injector.annotations.component.ConfigurationFile; -import net.dzikoysk.cdn.entity.Description; -import net.dzikoysk.cdn.source.Resource; -import net.dzikoysk.cdn.source.Source; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -@ConfigurationFile -public class WarpsConfiguration implements ReloadableConfig { - - @Description({"# Warps configuration", "# These are warp locations, for your own safety, please don't touch it."}) - public Map warps = new HashMap<>(); - - @Override - public Resource resource(File folder) { - return Source.of(folder, "warps.yml"); - } - -} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java deleted file mode 100644 index 510198152..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.eternalcode.core.feature.warp; - -import com.eternalcode.commons.bukkit.position.PositionAdapter; -import com.eternalcode.core.configuration.ConfigurationManager; -import com.eternalcode.core.configuration.implementation.LocationsConfiguration; -import com.eternalcode.core.configuration.implementation.WarpsConfiguration; -import com.eternalcode.core.injector.annotations.Inject; -import com.eternalcode.core.injector.annotations.component.Service; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -@Service -class WarpConfigRepository implements WarpRepository { - - private final LocationsConfiguration locationsConfiguration; - private final WarpsConfiguration warpsConfiguration; - private final ConfigurationManager configurationManager; - - @Inject - WarpConfigRepository( - ConfigurationManager configurationManager, - LocationsConfiguration locationsConfiguration, - WarpsConfiguration warpsConfiguration - ) { - this.locationsConfiguration = locationsConfiguration; - this.configurationManager = configurationManager; - this.warpsConfiguration = warpsConfiguration; - - this.migrateWarps(); - } - - @Override - public void addWarp(Warp warp) { - WarpConfigEntry warpConfigEntry = new WarpConfigEntry(PositionAdapter.convert(warp.getLocation()), warp.getPermissions()); - this.edit(warps -> warps.put( - warp.getName(), - warpConfigEntry - )); - } - - @Override - public void removeWarp(String warp) { - this.edit(warps -> warps.remove(warp)); - } - - @Override - public void addPermissions(String warp, String... permissions) { - this.edit(warps -> { - WarpConfigEntry warpConfigEntry = warps.get(warp); - if (warpConfigEntry == null) { - return; - } - - List newPermissions = new ArrayList<>(warpConfigEntry.permissions); - newPermissions.addAll(List.of(permissions)); - - warpConfigEntry.permissions = newPermissions; - }); - } - - @Override - public void removePermission(String warp, String permission) { - this.edit(warps -> { - WarpConfigEntry warpConfigEntry = warps.get(warp); - - if (warpConfigEntry == null) { - return; - } - - List newPermissions = new ArrayList<>(warpConfigEntry.permissions); - newPermissions.remove(permission); - - warpConfigEntry.permissions = newPermissions; - }); - } - - private void edit(Consumer> editor) { - Map warps = new HashMap<>(this.warpsConfiguration.warps); - editor.accept(warps); - - warps.forEach((key, value) -> System.out.println(key + ": " + value)); - this.warpsConfiguration.warps.putAll(warps); - this.configurationManager.save(this.warpsConfiguration); - } - - @Override - public CompletableFuture> getWarp(String name) { - return CompletableFuture.completedFuture(Optional.of(this.warpsConfiguration.warps.get(name)) - .map(warpConfigEntry -> new WarpImpl(name, warpConfigEntry.position, warpConfigEntry.permissions))); - } - - @Override - public CompletableFuture> getWarps() { - return CompletableFuture.completedFuture(this.warpsConfiguration.warps.entrySet().stream() - .map(warpConfigEntry -> { - WarpConfigEntry warpContextual = warpConfigEntry.getValue(); - return new WarpImpl(warpConfigEntry.getKey(), warpContextual.position, warpContextual.permissions); - }) - .collect(Collectors.toList())); - } - - private void migrateWarps() { - if (this.locationsConfiguration.warps.isEmpty()) { - return; - } - - this.edit(warps -> warps.putAll(this.locationsConfiguration.warps - .entrySet() - .stream() - .collect(Collectors.toMap(Map.Entry::getKey, entry -> - new WarpConfigEntry(entry.getValue(), new ArrayList<>())) - ) - )); - - this.locationsConfiguration.warps.clear(); - this.configurationManager.save(this.locationsConfiguration); - this.configurationManager.save(this.warpsConfiguration); - } -} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java index 46acae415..a948e6100 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java @@ -2,21 +2,23 @@ import com.eternalcode.commons.bukkit.position.Position; import com.eternalcode.commons.bukkit.position.PositionAdapter; +import java.util.ArrayList; import org.bukkit.Location; import java.util.Collections; import java.util.List; -class WarpImpl implements Warp { +@SuppressWarnings("LombokSetterMayBeUsed") +public class WarpImpl implements Warp { private final String name; private final Position position; private List permissions; - WarpImpl(String name, Position position, List permissions) { + public WarpImpl(String name, Position position, List permissions) { this.name = name; this.position = position; - this.permissions = permissions; + this.permissions = new ArrayList<>(permissions); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java index f2e9df6eb..184caa653 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java @@ -198,7 +198,7 @@ public void openInventory(Player player, Language language) { } public void addWarp(Warp warp) { - if (!this.warpManager.warpExists(warp.getName())) { + if (!this.warpManager.exists(warp.getName())) { return; } @@ -243,7 +243,7 @@ public void addWarp(Warp warp) { public boolean removeWarp(String warpName) { - if (!this.warpManager.warpExists(warpName)) { + if (!this.warpManager.exists(warpName)) { return false; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java index b01da97dd..8f39392eb 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java @@ -22,12 +22,12 @@ public class WarpPermissionController implements Listener { private final NoticeService noticeService; - private final PluginConfiguration pluginConfiguration; + private final PluginConfiguration config; @Inject - public WarpPermissionController(NoticeService noticeService, PluginConfiguration pluginConfiguration) { + public WarpPermissionController(NoticeService noticeService, PluginConfiguration config) { this.noticeService = noticeService; - this.pluginConfiguration = pluginConfiguration; + this.config = config; } @EventHandler @@ -55,6 +55,7 @@ private void checkWarpPermission(PreWarpTeleportEvent event, Warp warp, Player p this.noticeService.create() .player(uniqueId) .placeholder("{WARP}", warp.getName()) + .placeholder("{PERMISSIONS}", String.join(this.config.format.separator, permissions)) .notice(translation -> translation.warp().noPermission()) .send(); } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java deleted file mode 100644 index b6914269e..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.eternalcode.core.feature.warp; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; - -interface WarpRepository { - - void addWarp(Warp warp); - - void removeWarp(String warp); - - void addPermissions(String warp, String... permissions); - - void removePermission(String warp, String permission); - - CompletableFuture> getWarp(String name); - - CompletableFuture> getWarps(); -} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java index 71f9eeb26..90b3a8931 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java @@ -2,17 +2,18 @@ import com.eternalcode.annotations.scan.feature.FeatureDocs; import com.eternalcode.commons.bukkit.position.PositionAdapter; +import com.eternalcode.core.feature.warp.data.WarpDataRepository; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; -import org.bukkit.Location; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; +import org.bukkit.Location; @FeatureDocs( name = "Warp System", @@ -21,33 +22,33 @@ @Service class WarpServiceImpl implements WarpService { - private final Map warpMap = new HashMap<>(); - private final WarpRepository warpRepository; + private final Map warps = new ConcurrentHashMap<>(); + private final WarpDataRepository warpRepository; @Inject - private WarpServiceImpl(WarpRepository warpRepository) { + private WarpServiceImpl(WarpDataRepository warpRepository) { this.warpRepository = warpRepository; warpRepository.getWarps().thenAcceptAsync(warps -> { for (Warp warp : warps) { - this.warpMap.put(warp.getName(), warp); + this.warps.put(warp.getName(), warp); } }); } @Override - public Warp createWarp(String name, Location location) { + public Warp create(String name, Location location) { Warp warp = new WarpImpl(name, PositionAdapter.convert(location), new ArrayList<>()); - this.warpMap.put(name, warp); + this.warps.put(name, warp); this.warpRepository.addWarp(warp); return warp; } @Override - public void removeWarp(String warp) { - Warp remove = this.warpMap.remove(warp); + public void delete(String warp) { + Warp remove = this.warps.remove(warp); if (remove == null) { return; @@ -58,42 +59,62 @@ public void removeWarp(String warp) { @Override public void addPermissions(String warpName, String... permissions) { - Warp warp = this.warpMap.get(warpName); + Warp warp = this.warps.get(warpName); if (warp == null) { return; } + if (permissions == null) { + return; + } + List updatedPermissions = new ArrayList<>(warp.getPermissions()); updatedPermissions.addAll(List.of(permissions)); - warp.setPermissions(updatedPermissions); + this.modifyPermissions(warpName, perms -> perms.addAll(List.of(permissions))); this.warpRepository.addPermissions(warpName, permissions); } @Override public void removePermission(String warpName, String permission) { - Warp warp = this.warpMap.get(warpName); + Warp warp = this.warps.get(warpName); + + if (warp == null) { + return; + } + + this.modifyPermissions(warpName, perms -> perms.remove(permission)); + this.warpRepository.removePermission(warpName, permission); + } + + private void modifyPermissions(String warpName, Consumer> modifier) { + Warp warp = this.warps.get(warpName); if (warp == null) { return; } List updatedPermissions = new ArrayList<>(warp.getPermissions()); - updatedPermissions.remove(permission); + modifier.accept(updatedPermissions); - warp.setPermissions(updatedPermissions); - this.warpRepository.removePermission(warpName, permission); + Warp updatedWarp = new WarpImpl( + warp.getName(), + PositionAdapter.convert(warp.getLocation()), + updatedPermissions + ); + + this.warps.put(warpName, updatedWarp); } @Override - public boolean warpExists(String name) { - return this.warpMap.containsKey(name); + public boolean exists(String name) { + return this.warps.containsKey(name); } @Override - public boolean doestWarpPermissionExist(String warpName, String permission) { - Warp warp = this.warpMap.get(warpName); + public boolean hasPermission(String warpName, String permission) { + Warp warp = this.warps.get(warpName); if (warp == null) { return false; @@ -104,16 +125,16 @@ public boolean doestWarpPermissionExist(String warpName, String permission) { @Override public Optional findWarp(String name) { - return Optional.ofNullable(this.warpMap.get(name)); + return Optional.ofNullable(this.warps.get(name)); } @Override - public Collection getNamesOfWarps() { - return Collections.unmodifiableCollection(this.warpMap.keySet()); + public Collection getAllNames() { + return Collections.unmodifiableCollection(this.warps.keySet()); } @Override - public boolean hasWarps() { - return !this.warpMap.isEmpty(); + public boolean isEmpty() { + return !this.warps.isEmpty(); } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java index c76774b25..816d68aa9 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java @@ -37,7 +37,7 @@ void remove(@Context Player player, @Arg Warp warp) { } private void removeWarp(Player player, String name) { - if (!this.warpService.warpExists(name)) { + if (!this.warpService.exists(name)) { this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().notExist()) @@ -47,7 +47,7 @@ private void removeWarp(Player player, String name) { return; } - this.warpService.removeWarp(name); + this.warpService.delete(name); this.warpInventory.removeWarp(name); this.noticeService.create() diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java index 288f14b34..a11db47a4 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java @@ -44,7 +44,7 @@ void add(@Context Player player, @Arg String warpName) { } private void createWarp(Player player, String warp, UUID uniqueId) { - if (this.warpService.warpExists(warp)) { + if (this.warpService.exists(warp)) { this.noticeService.create() .player(uniqueId) .notice(translation -> translation.warp().warpAlreadyExists()) @@ -54,7 +54,7 @@ private void createWarp(Player player, String warp, UUID uniqueId) { return; } - Warp createdWarp = this.warpService.createWarp(warp, player.getLocation()); + Warp createdWarp = this.warpService.create(warp, player.getLocation()); this.noticeService.create() .player(uniqueId) @@ -63,7 +63,7 @@ private void createWarp(Player player, String warp, UUID uniqueId) { .send(); if (this.config.warp.autoAddNewWarps) { - if (this.warpService.getNamesOfWarps().size() <= MAX_WARPS_IN_GUI) { + if (this.warpService.getAllNames().size() <= MAX_WARPS_IN_GUI) { this.warpInventory.addWarp(createdWarp); this.noticeService.create() diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java index 5b5b6946b..40526f207 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java @@ -58,7 +58,7 @@ public SuggestionResult suggest( Argument argument, SuggestionContext context ) { - return this.warpService.getNamesOfWarps().stream() + return this.warpService.getAllNames().stream() .collect(SuggestionResult.collector()); } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java index ec5f12370..bf5c480c5 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java @@ -48,13 +48,13 @@ void warp(@Context Player player, @Context User user) { this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().available()) - .placeholder("{WARPS}", String.join(", ", this.warpService.getNamesOfWarps())) + .placeholder("{WARPS}", String.join(", ", this.warpService.getAllNames())) .send(); return; } - if (!this.warpService.hasWarps()) { + if (!this.warpService.isEmpty()) { this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().noWarps()) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/AddWarpPermissionCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpAddPermissionCommand.java similarity index 88% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/AddWarpPermissionCommand.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpAddPermissionCommand.java index ecbe78185..69057d289 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/AddWarpPermissionCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpAddPermissionCommand.java @@ -1,4 +1,4 @@ -package com.eternalcode.core.feature.warp.command; +package com.eternalcode.core.feature.warp.command.permission; import com.eternalcode.core.feature.warp.Warp; import com.eternalcode.core.feature.warp.WarpService; @@ -13,15 +13,15 @@ import java.util.UUID; -@Command(name = "addwarp-permissions") +@Command(name = "warp-permission add") @Permission("eternalcore.warp.changepermissions") -public class AddWarpPermissionCommand { +public class WarpAddPermissionCommand { private final WarpService warpService; private final NoticeService noticeService; @Inject - public AddWarpPermissionCommand(WarpService warpService, NoticeService noticeService) { + public WarpAddPermissionCommand(WarpService warpService, NoticeService noticeService) { this.warpService = warpService; this.noticeService = noticeService; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/RemoveWarpPermissionCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java similarity index 68% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/RemoveWarpPermissionCommand.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java index c71bddb5a..852c87be7 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/RemoveWarpPermissionCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java @@ -1,7 +1,8 @@ -package com.eternalcode.core.feature.warp.command; +package com.eternalcode.core.feature.warp.command.permission; import com.eternalcode.core.feature.warp.Warp; import com.eternalcode.core.feature.warp.WarpService; +import com.eternalcode.core.feature.warp.command.permission.argument.WarpPermissionMultipleResolverEntry; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.notice.NoticeService; import dev.rollczi.litecommands.annotations.argument.Arg; @@ -11,29 +12,32 @@ import dev.rollczi.litecommands.annotations.permission.Permission; import org.bukkit.entity.Player; -import java.util.UUID; - -@Command(name = "removewarp-permission") +@Command(name = "warp-permission remove") @Permission("eternalcore.warp.changepermissions") -public class RemoveWarpPermissionCommand { +public class WarpRemovePermissionCommand { private final WarpService warpService; private final NoticeService noticeService; @Inject - public RemoveWarpPermissionCommand(WarpService warpService, NoticeService noticeService) { + public WarpRemovePermissionCommand(WarpService warpService, NoticeService noticeService) { this.warpService = warpService; this.noticeService = noticeService; } @Execute - void removePermission(@Context Player player, @Arg Warp warp, @Arg String permission) { - UUID uniqueId = player.getUniqueId(); + void removePermission( + @Context Player player, + @Arg WarpPermissionMultipleResolverEntry entry + ) { + Warp warp = entry.warp(); + String permission = entry.permission(); if (!warp.getPermissions().contains(permission)) { this.noticeService.create() - .player(uniqueId) + .placeholder("{WARP}", warp.getName()) .placeholder("{PERMISSION}", permission) + .player(player.getUniqueId()) .notice(translation -> translation.warp().permissionDoesNotExist()) .send(); return; @@ -42,11 +46,10 @@ void removePermission(@Context Player player, @Arg Warp warp, @Arg String permis this.warpService.removePermission(warp.getName(), permission); this.noticeService.create() - .player(uniqueId) .placeholder("{WARP}", warp.getName()) .placeholder("{PERMISSION}", permission) + .player(player.getUniqueId()) .notice(translation -> translation.warp().removePermission()) .send(); } - } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java new file mode 100644 index 000000000..f2eab3979 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java @@ -0,0 +1,138 @@ +package com.eternalcode.core.feature.warp.command.permission.argument; + +import com.eternalcode.core.configuration.implementation.PluginConfiguration; +import com.eternalcode.core.feature.warp.Warp; +import com.eternalcode.core.feature.warp.WarpService; +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.injector.annotations.lite.LiteArgument; +import com.eternalcode.core.notice.NoticeService; +import com.eternalcode.core.viewer.Viewer; +import com.eternalcode.core.viewer.ViewerService; +import dev.rollczi.litecommands.argument.Argument; +import dev.rollczi.litecommands.argument.parser.ParseResult; +import dev.rollczi.litecommands.argument.resolver.MultipleArgumentResolver; +import dev.rollczi.litecommands.input.raw.RawInput; +import dev.rollczi.litecommands.invocation.Invocation; +import dev.rollczi.litecommands.range.Range; +import dev.rollczi.litecommands.suggestion.Suggestion; +import dev.rollczi.litecommands.suggestion.SuggestionContext; +import dev.rollczi.litecommands.suggestion.SuggestionResult; +import java.util.Collection; +import java.util.Optional; +import org.bukkit.command.CommandSender; + +@LiteArgument(type = WarpPermissionMultipleResolverEntry.class) +public class WarpPermissionMultiArgumentResolver + implements MultipleArgumentResolver { + + private static final String WARP_PLACEHOLDER_PREFIX = "{WARP}"; + private static final String PERMISSION_PLACEHOLDER_PREFIX = "{PERMISSION}"; + + private final PluginConfiguration config; + private final WarpService warpService; + private final NoticeService noticeService; + private final ViewerService viewerService; + + @Inject + public WarpPermissionMultiArgumentResolver( + PluginConfiguration config, + WarpService warpService, + NoticeService noticeService, + ViewerService viewerService + ) { + this.config = config; + this.warpService = warpService; + this.noticeService = noticeService; + this.viewerService = viewerService; + } + + @Override + public ParseResult parse( + Invocation invocation, + Argument argument, + RawInput rawInput + ) { + Viewer viewer = this.viewerService.any(invocation.sender()); + + if (!rawInput.hasNext()) { + return ParseResult.failure(this.noticeService.create() + .notice(translation -> translation.warp().missingWarpName()) + .viewer(viewer) + ); + } + + String warpName = rawInput.next(); + Optional warp = this.warpService.findWarp(warpName); + + if (warp.isEmpty()) { + return ParseResult.failure( + this.noticeService.create() + .notice(translation -> translation.warp().notExist()) + .placeholder(WARP_PLACEHOLDER_PREFIX, warpName) + .viewer(viewer) + ); + } + + if (!rawInput.hasNext()) { + Collection permissions = warp.get().getPermissions(); + + if (permissions.isEmpty()) { + return ParseResult.failure(this.noticeService.create() + .notice(translation -> translation.warp().noPermissionAssigned()) + .placeholder(WARP_PLACEHOLDER_PREFIX, warpName) + .viewer(viewer) + ); + } + + return ParseResult.failure(this.noticeService.create() + .notice(translation -> translation.warp().listPermission()) + .placeholder(WARP_PLACEHOLDER_PREFIX, warpName) + .placeholder(PERMISSION_PLACEHOLDER_PREFIX, String.join(this.config.format.separator, permissions)) + .viewer(viewer) + ); + } + + String permission = rawInput.next(); + + return ParseResult.success(new WarpPermissionMultipleResolverEntry(warp.get(), permission)); + } + + @Override + public Range getRange(Argument argument) { + return Range.of(2); + } + + @Override + public SuggestionResult suggest( + Invocation invocation, + Argument argument, + SuggestionContext context + ) { + Suggestion current = context.getCurrent(); + int index = current.lengthMultilevel(); + + if (index == 1) { + return SuggestionResult.of(this.warpService.getAllNames()); + } + + if (index == 2) { + String warpName = current.multilevelList().get(0); + Optional warpOptional = this.warpService.findWarp(warpName); + + if (warpOptional.isEmpty()) { + return SuggestionResult.empty(); + } + + Warp warp = warpOptional.get(); + Collection permissions = warp.getPermissions(); + + if (permissions.isEmpty()) { + return SuggestionResult.empty(); + } + + return SuggestionResult.of(permissions).appendLeft(warpName); + } + + return SuggestionResult.empty(); + } +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultipleResolverEntry.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultipleResolverEntry.java new file mode 100644 index 000000000..a0e3beb6d --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultipleResolverEntry.java @@ -0,0 +1,6 @@ +package com.eternalcode.core.feature.warp.command.permission.argument; + +import com.eternalcode.core.feature.warp.Warp; + +public record WarpPermissionMultipleResolverEntry(Warp warp, String permission) { +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfig.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfig.java new file mode 100644 index 000000000..5e13c12c0 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfig.java @@ -0,0 +1,26 @@ +package com.eternalcode.core.feature.warp.data; + +import com.eternalcode.core.configuration.ReloadableConfig; +import com.eternalcode.core.injector.annotations.component.ConfigurationFile; +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import net.dzikoysk.cdn.entity.Description; +import net.dzikoysk.cdn.entity.Exclude; +import net.dzikoysk.cdn.source.Resource; +import net.dzikoysk.cdn.source.Source; + +@ConfigurationFile +public class WarpDataConfig implements ReloadableConfig { + + @Exclude + public static final String WARP_DATA_FILE_PATH = "data" + File.separator + "warps.yml"; + + @Description({"# Warps data", "# These are warp locations, for your own safety, please don't touch it."}) + public Map warps = new HashMap<>(); + + @Override + public Resource resource(File folder) { + return Source.of(folder, WARP_DATA_FILE_PATH); + } +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigEntry.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java similarity index 57% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigEntry.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java index bfa64e7da..c37ae603c 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigEntry.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java @@ -1,19 +1,18 @@ -package com.eternalcode.core.feature.warp; +package com.eternalcode.core.feature.warp.data; import com.eternalcode.commons.bukkit.position.Position; -import net.dzikoysk.cdn.entity.Contextual; - import java.util.List; +import net.dzikoysk.cdn.entity.Contextual; @Contextual -public class WarpConfigEntry { +public class WarpDataConfigRepresenter { public Position position; public List permissions; - public WarpConfigEntry() { + public WarpDataConfigRepresenter() { } - public WarpConfigEntry(Position position, List permissions) { + public WarpDataConfigRepresenter(Position position, List permissions) { this.position = position; this.permissions = permissions; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java new file mode 100644 index 000000000..fca475451 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java @@ -0,0 +1,129 @@ +package com.eternalcode.core.feature.warp.data; + +import com.eternalcode.commons.bukkit.position.PositionAdapter; +import com.eternalcode.core.configuration.ConfigurationManager; +import com.eternalcode.core.configuration.implementation.LocationsConfiguration; +import com.eternalcode.core.feature.warp.Warp; +import com.eternalcode.core.feature.warp.WarpImpl; +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.injector.annotations.component.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +@Service +public class WarpDataDataRepositoryImpl implements WarpDataRepository { + + private final LocationsConfiguration locationsConfiguration; + private final WarpDataConfig warpDataConfig; + private final ConfigurationManager configurationManager; + + @Inject + WarpDataDataRepositoryImpl( + ConfigurationManager configurationManager, + LocationsConfiguration locationsConfiguration, + WarpDataConfig warpDataConfig + ) { + this.locationsConfiguration = locationsConfiguration; + this.configurationManager = configurationManager; + this.warpDataConfig = warpDataConfig; + + this.migrateWarps(); + } + + @Override + public CompletableFuture addWarp(Warp warp) { + return CompletableFuture.runAsync(() -> { + WarpDataConfigRepresenter warpDataConfigRepresenter = new WarpDataConfigRepresenter( + PositionAdapter.convert(warp.getLocation()), + warp.getPermissions() + ); + + this.edit(warps -> warps.put(warp.getName(), warpDataConfigRepresenter)); + }); + } + + @Override + public CompletableFuture removeWarp(String warp) { + return CompletableFuture.runAsync(() -> this.edit(warps -> warps.remove(warp))); + } + @Override + public CompletableFuture addPermissions(String warp, String... permissions) { + return CompletableFuture.runAsync(() -> this.edit(warps -> { + WarpDataConfigRepresenter warpDataConfigRepresenter = warps.get(warp); + if (warpDataConfigRepresenter == null) { + return; + } + + List newPermissions = new ArrayList<>(warpDataConfigRepresenter.permissions); + newPermissions.addAll(List.of(permissions)); + + warpDataConfigRepresenter.permissions = newPermissions; + })); + } + + @Override + public CompletableFuture removePermission(String warp, String permission) { + return CompletableFuture.runAsync(() -> this.edit(warps -> { + WarpDataConfigRepresenter warpDataConfigRepresenter = warps.get(warp); + + if (warpDataConfigRepresenter == null) { + return; + } + + List newPermissions = new ArrayList<>(warpDataConfigRepresenter.permissions); + newPermissions.remove(permission); + + warpDataConfigRepresenter.permissions = newPermissions; + })); + } + + private void edit(Consumer> editor) { + synchronized (warpDataConfig.warps) { + Map warps = new HashMap<>(this.warpDataConfig.warps); + editor.accept(warps); + this.warpDataConfig.warps.putAll(warps); + } + this.configurationManager.save(this.warpDataConfig); + } + + @Override + public CompletableFuture> getWarp(String name) { + return CompletableFuture.completedFuture(Optional.of(this.warpDataConfig.warps.get(name)) + .map(warpDataConfigRepresenter -> new WarpImpl(name, warpDataConfigRepresenter.position, warpDataConfigRepresenter.permissions))); + } + + @Override + public CompletableFuture> getWarps() { + return CompletableFuture.completedFuture(this.warpDataConfig.warps.entrySet().stream() + .map(warpConfigEntry -> { + WarpDataConfigRepresenter warpContextual = warpConfigEntry.getValue(); + return new WarpImpl(warpConfigEntry.getKey(), warpContextual.position, warpContextual.permissions); + }) + .collect(Collectors.toList())); + } + + private void migrateWarps() { + if (this.locationsConfiguration.warps.isEmpty()) { + return; + } + + this.edit(warps -> warps.putAll(this.locationsConfiguration.warps + .entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> + new WarpDataConfigRepresenter(entry.getValue(), new ArrayList<>())) + ) + )); + + this.locationsConfiguration.warps.clear(); + this.configurationManager.save(this.locationsConfiguration); + this.configurationManager.save(this.warpDataConfig); + } +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java new file mode 100644 index 000000000..11a6bb8a4 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java @@ -0,0 +1,21 @@ +package com.eternalcode.core.feature.warp.data; + +import com.eternalcode.core.feature.warp.Warp; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +public interface WarpDataRepository { + + CompletableFuture addWarp(Warp warp); + + CompletableFuture removeWarp(String warp); + + CompletableFuture addPermissions(String warp, String... permissions); + + CompletableFuture removePermission(String warp, String permission); + + CompletableFuture> getWarp(String name); + + CompletableFuture> getWarps(); +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java index 8f0762b14..8317275c3 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java @@ -157,6 +157,9 @@ interface WarpSection { Notice removePermission(); Notice permissionDoesNotExist(); Notice noPermissionsProvided(); + Notice noPermissionAssigned(); + Notice missingWarpName(); + Notice listPermission(); WarpInventorySection warpInventory(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java index cc93e15e2..eac3396dc 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java @@ -387,6 +387,9 @@ public static class ENWarpSection implements WarpSection { public Notice removePermission = Notice.chat("Removed permission {PERMISSION} from warp {WARP}!"); public Notice noPermissionsProvided = Notice.chat("No permissions provided!"); public Notice permissionDoesNotExist = Notice.chat("Permission {PERMISSION} doesn't exist!"); + public Notice noPermissionAssigned = Notice.chat("There are no permissions assigned to this warp!"); + public Notice missingWarpName = Notice.chat("You must provide a warp name!"); + public Notice listPermission = Notice.chat("Permissions for warp {WARP}: {PERMISSIONS}"); @Description({" ", "# {WARPS} - List of warps (separated by commas)"}) public Notice available = Notice.chat("Available warps: {WARPS}"); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index 2a2a224d1..f98bfd126 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -106,7 +106,7 @@ public static class PLArgumentSection implements ArgumentSection { public Notice usageMessageEntry = Notice.chat("{USAGE}"); @Description(" ") - public Notice missingPlayerName = Notice.chat("Błąd: Musisz podać nazwę gracza!"); + public Notice missingPlayerName = Notice.chat("Musisz podać nazwę gracza!"); public Notice offlinePlayer = Notice.chat("Ten gracz jest obecnie offline!"); public Notice onlyPlayer = Notice.chat("Ta komenda jest dostępna tylko dla graczy!"); public Notice numberBiggerThanOrEqualZero = Notice.chat("Liczba musi być równa lub większa od 0!"); @@ -308,7 +308,7 @@ public static class PLChatSection implements ChatSection { public Notice alertQueueAdded = Notice.chat("Dodano wiadomość do kolejki!"); public Notice alertQueueRemoved = Notice.chat("Usunięto wiadomość z kolejki!"); public Notice alertQueueCleared = Notice.chat("Wyczyszczono kolejkę wiadomości!"); - public Notice alertQueueEmpty = Notice.chat("Błąd: Kolejka wiadomości jest pusta!"); + public Notice alertQueueEmpty = Notice.chat("Kolejka wiadomości jest pusta!"); public Notice alertQueueSent = Notice.chat("Wysłano wszystkie wiadomości z kolejki!"); } @@ -385,14 +385,19 @@ public static class PLWarpSection implements WarpSection { public Notice itemAdded = Notice.chat("Dodano warp do GUI!"); public Notice noWarps = Notice.chat("Nie ma dostępnych warpów!"); public Notice itemLimit = Notice.chat("Osiągnąłeś limit warpów w GUI! Limit to: {LIMIT}!"); - public Notice noPermission = Notice.chat("Nie masz uprawnień do skorzystania z tego warpa ({WARP})!"); + public Notice noPermission = Notice.chat("Nie masz uprawnień do skorzystania z tego warpa {WARP}!"); public Notice addPermissions = Notice.chat("Dodano uprawnienia do warpa {WARP}!"); - public Notice removePermission = Notice.chat("Usunięto uprawnienie {PERMISSION} do warpa {WARP}!"); - public Notice noPermissionsProvided = Notice.chat("Błąd: Nie podano żadnych uprawnień!"); - public Notice permissionDoesNotExist = Notice.chat("Błąd: Podane uprawnienie nie istnieje ({PERMISSION})!"); + public Notice removePermission = Notice.chat("Usunięto uprawnienie {PERMISSION} z warpa {WARP}!"); + public Notice noPermissionsProvided = Notice.chat("Nie podano żadnych uprawnień!"); + public Notice permissionDoesNotExist = Notice.chat("Podane uprawnienie nie istnieje ({PERMISSION})!"); + public Notice noPermissionAssigned = Notice.chat("Ten warp nie ma przypisanych żadnych permisji"); + public Notice missingWarpName = Notice.chat("Musisz podać nazwę warpu!"); + public Notice listPermission = Notice.chat("Lista uprawnień dla warpa {WARP}: {PERMISSIONS}!"); + @Description({" ", "# {WARPS} - Lista dostępnych warpów"}) public Notice available = Notice.chat("Dostepne warpy: {WARPS}!"); + @Description({" ", "# Ustawienia gui listy dostępnych warpów"}) public PLWarpInventory warpInventory = new PLWarpInventory(); @@ -468,7 +473,7 @@ public static class PLHomeSection implements HomeSection { "# {HOME} - Nazwa domu, {PLAYER} - Gracz, {HOMES} - Lista domów" }) public Notice overrideHomeLocationAsAdmin = Notice.chat("Nadpisałeś lokalizację domu {HOME} dla gracza {PLAYER}!"); - public Notice playerNoOwnedHomes = Notice.chat("Błąd: Gracz {PLAYER} nie posiada żadnego domu!"); + public Notice playerNoOwnedHomes = Notice.chat("Gracz {PLAYER} nie posiada żadnego domu!"); public Notice createAsAdmin = Notice.chat("Stworzono dom {HOME} dla gracza {PLAYER}!"); public Notice deleteAsAdmin = Notice.chat("Usunięto dom {HOME} dla gracza {PLAYER}!"); public Notice homeListAsAdmin = Notice.chat("Lista domów gracza {PLAYER}: {HOMES}!"); From 0aaf2269012aeef9519be4b1bdfad95b8762830d Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 14:05:01 +0100 Subject: [PATCH 06/21] Update eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../core/translation/implementation/PLTranslation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index f98bfd126..86320b1f3 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -106,7 +106,7 @@ public static class PLArgumentSection implements ArgumentSection { public Notice usageMessageEntry = Notice.chat("{USAGE}"); @Description(" ") - public Notice missingPlayerName = Notice.chat("Musisz podać nazwę gracza!"); + public Notice missingPlayerName = Notice.chat("Musisz podać nazwę gracza!"); public Notice offlinePlayer = Notice.chat("Ten gracz jest obecnie offline!"); public Notice onlyPlayer = Notice.chat("Ta komenda jest dostępna tylko dla graczy!"); public Notice numberBiggerThanOrEqualZero = Notice.chat("Liczba musi być równa lub większa od 0!"); From bf890c7fac217e387cf8e001414c9ac129d16e57 Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 14:05:47 +0100 Subject: [PATCH 07/21] Update eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../core/translation/implementation/PLTranslation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index 86320b1f3..f72840080 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -308,7 +308,7 @@ public static class PLChatSection implements ChatSection { public Notice alertQueueAdded = Notice.chat("Dodano wiadomość do kolejki!"); public Notice alertQueueRemoved = Notice.chat("Usunięto wiadomość z kolejki!"); public Notice alertQueueCleared = Notice.chat("Wyczyszczono kolejkę wiadomości!"); - public Notice alertQueueEmpty = Notice.chat("Kolejka wiadomości jest pusta!"); + public Notice alertQueueEmpty = Notice.chat("Kolejka wiadomości jest pusta!"); public Notice alertQueueSent = Notice.chat("Wysłano wszystkie wiadomości z kolejki!"); } From d11676fd33487cf68f0aaf7d5a35103190d3c289 Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 14:06:20 +0100 Subject: [PATCH 08/21] Update eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../core/translation/implementation/PLTranslation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index f72840080..078a3becf 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -473,7 +473,7 @@ public static class PLHomeSection implements HomeSection { "# {HOME} - Nazwa domu, {PLAYER} - Gracz, {HOMES} - Lista domów" }) public Notice overrideHomeLocationAsAdmin = Notice.chat("Nadpisałeś lokalizację domu {HOME} dla gracza {PLAYER}!"); - public Notice playerNoOwnedHomes = Notice.chat("Gracz {PLAYER} nie posiada żadnego domu!"); + public Notice playerNoOwnedHomes = Notice.chat("Gracz {PLAYER} nie posiada żadnego domu!"); public Notice createAsAdmin = Notice.chat("Stworzono dom {HOME} dla gracza {PLAYER}!"); public Notice deleteAsAdmin = Notice.chat("Usunięto dom {HOME} dla gracza {PLAYER}!"); public Notice homeListAsAdmin = Notice.chat("Lista domów gracza {PLAYER}: {HOMES}!"); From 2804b53f6e29baacb5e787a799ecc35b15af9415 Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 14:07:38 +0100 Subject: [PATCH 09/21] Update eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../java/com/eternalcode/core/feature/warp/WarpServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java index 90b3a8931..b5503eb87 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java @@ -135,6 +135,6 @@ public Collection getAllNames() { @Override public boolean isEmpty() { - return !this.warps.isEmpty(); + return this.warps.isEmpty(); } } From a8ac2e2cbe30bcb3b6ca20aa944b9a0632db5c14 Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 14:08:40 +0100 Subject: [PATCH 10/21] Update eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../core/feature/warp/data/WarpDataDataRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java index fca475451..1527a3ab8 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java @@ -89,8 +89,8 @@ private void edit(Consumer> editor) { Map warps = new HashMap<>(this.warpDataConfig.warps); editor.accept(warps); this.warpDataConfig.warps.putAll(warps); + this.configurationManager.save(this.warpDataConfig); } - this.configurationManager.save(this.warpDataConfig); } @Override From 708224f5ff7cd18fa4f248c9027d2a213468f97d Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 14:09:38 +0100 Subject: [PATCH 11/21] Update eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../core/feature/warp/data/WarpDataDataRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java index 1527a3ab8..153a446ff 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java @@ -95,7 +95,7 @@ private void edit(Consumer> editor) { @Override public CompletableFuture> getWarp(String name) { - return CompletableFuture.completedFuture(Optional.of(this.warpDataConfig.warps.get(name)) + return CompletableFuture.completedFuture(Optional.ofNullable(this.warpDataConfig.warps.get(name)) .map(warpDataConfigRepresenter -> new WarpImpl(name, warpDataConfigRepresenter.position, warpDataConfigRepresenter.permissions))); } From 2a67403864cbd508d60f64ce19b3596be6267865 Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 14:22:58 +0100 Subject: [PATCH 12/21] Fix repository name, check if permission already exist. --- .../permission/WarpAddPermissionCommand.java | 29 +++++++++++++++---- ...yImpl.java => WarpDataRepositoryImpl.java} | 26 ++++++++--------- .../core/translation/Translation.java | 1 + .../implementation/ENTranslation.java | 1 + .../implementation/PLTranslation.java | 1 + 5 files changed, 39 insertions(+), 19 deletions(-) rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/{WarpDataDataRepositoryImpl.java => WarpDataRepositoryImpl.java} (83%) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpAddPermissionCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpAddPermissionCommand.java index 69057d289..86ff4159c 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpAddPermissionCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpAddPermissionCommand.java @@ -1,5 +1,6 @@ package com.eternalcode.core.feature.warp.command.permission; +import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.feature.warp.Warp; import com.eternalcode.core.feature.warp.WarpService; import com.eternalcode.core.injector.annotations.Inject; @@ -9,19 +10,23 @@ import dev.rollczi.litecommands.annotations.context.Context; import dev.rollczi.litecommands.annotations.execute.Execute; import dev.rollczi.litecommands.annotations.permission.Permission; -import org.bukkit.entity.Player; - +import java.util.Arrays; +import java.util.Collection; +import java.util.List; import java.util.UUID; +import org.bukkit.entity.Player; @Command(name = "warp-permission add") @Permission("eternalcore.warp.changepermissions") public class WarpAddPermissionCommand { + private final PluginConfiguration config; private final WarpService warpService; private final NoticeService noticeService; @Inject - public WarpAddPermissionCommand(WarpService warpService, NoticeService noticeService) { + public WarpAddPermissionCommand(PluginConfiguration config, WarpService warpService, NoticeService noticeService) { + this.config = config; this.warpService = warpService; this.noticeService = noticeService; } @@ -38,7 +43,22 @@ void addPermission(@Context Player player, @Arg Warp warp, @Arg String... permis return; } - this.warpService.addPermissions(warp.getName(), permissions); + Collection currentPermissions = warp.getPermissions(); + + List newPermissions = Arrays.stream(permissions) + .filter(permission -> !currentPermissions.contains(permission)) + .toList(); + + if (newPermissions.isEmpty()) { + this.noticeService.create() + .player(uniqueId) + .placeholder("{WARP}", warp.getName()) + .placeholder("{PERMISSION}", String.join(this.config.format.separator, permissions)) + .notice(translation -> translation.warp().permissionAlreadyExist()) + .send(); + return; + } + this.warpService.addPermissions(warp.getName(), newPermissions.toArray(new String[0])); this.noticeService.create() .player(uniqueId) @@ -46,5 +66,4 @@ void addPermission(@Context Player player, @Arg Warp warp, @Arg String... permis .notice(translation -> translation.warp().addPermissions()) .send(); } - } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java similarity index 83% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java index 153a446ff..854af27ee 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataDataRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java @@ -7,7 +7,6 @@ import com.eternalcode.core.feature.warp.WarpImpl; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -18,14 +17,14 @@ import java.util.stream.Collectors; @Service -public class WarpDataDataRepositoryImpl implements WarpDataRepository { +public class WarpDataRepositoryImpl implements WarpDataRepository { private final LocationsConfiguration locationsConfiguration; private final WarpDataConfig warpDataConfig; private final ConfigurationManager configurationManager; @Inject - WarpDataDataRepositoryImpl( + WarpDataRepositoryImpl( ConfigurationManager configurationManager, LocationsConfiguration locationsConfiguration, WarpDataConfig warpDataConfig @@ -53,6 +52,7 @@ public CompletableFuture addWarp(Warp warp) { public CompletableFuture removeWarp(String warp) { return CompletableFuture.runAsync(() -> this.edit(warps -> warps.remove(warp))); } + @Override public CompletableFuture addPermissions(String warp, String... permissions) { return CompletableFuture.runAsync(() -> this.edit(warps -> { @@ -61,10 +61,7 @@ public CompletableFuture addPermissions(String warp, String... permissions return; } - List newPermissions = new ArrayList<>(warpDataConfigRepresenter.permissions); - newPermissions.addAll(List.of(permissions)); - - warpDataConfigRepresenter.permissions = newPermissions; + warpDataConfigRepresenter.permissions.addAll(List.of(permissions)); })); } @@ -77,10 +74,7 @@ public CompletableFuture removePermission(String warp, String permission) return; } - List newPermissions = new ArrayList<>(warpDataConfigRepresenter.permissions); - newPermissions.remove(permission); - - warpDataConfigRepresenter.permissions = newPermissions; + warpDataConfigRepresenter.permissions.remove(permission); })); } @@ -96,7 +90,10 @@ private void edit(Consumer> editor) { @Override public CompletableFuture> getWarp(String name) { return CompletableFuture.completedFuture(Optional.ofNullable(this.warpDataConfig.warps.get(name)) - .map(warpDataConfigRepresenter -> new WarpImpl(name, warpDataConfigRepresenter.position, warpDataConfigRepresenter.permissions))); + .map(warpDataConfigRepresenter -> new WarpImpl( + name, + warpDataConfigRepresenter.position, + warpDataConfigRepresenter.permissions))); } @Override @@ -117,8 +114,9 @@ private void migrateWarps() { this.edit(warps -> warps.putAll(this.locationsConfiguration.warps .entrySet() .stream() - .collect(Collectors.toMap(Map.Entry::getKey, entry -> - new WarpDataConfigRepresenter(entry.getValue(), new ArrayList<>())) + .collect(Collectors.toMap( + Map.Entry::getKey, entry -> + new WarpDataConfigRepresenter(entry.getValue(), new ArrayList<>())) ) )); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java index 8317275c3..2dbc258c9 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java @@ -156,6 +156,7 @@ interface WarpSection { Notice addPermissions(); Notice removePermission(); Notice permissionDoesNotExist(); + Notice permissionAlreadyExist(); Notice noPermissionsProvided(); Notice noPermissionAssigned(); Notice missingWarpName(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java index eac3396dc..28ff3db8e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java @@ -387,6 +387,7 @@ public static class ENWarpSection implements WarpSection { public Notice removePermission = Notice.chat("Removed permission {PERMISSION} from warp {WARP}!"); public Notice noPermissionsProvided = Notice.chat("No permissions provided!"); public Notice permissionDoesNotExist = Notice.chat("Permission {PERMISSION} doesn't exist!"); + public Notice permissionAlreadyExist = Notice.chat("Permission {PERMISSION} already exists!"); public Notice noPermissionAssigned = Notice.chat("There are no permissions assigned to this warp!"); public Notice missingWarpName = Notice.chat("You must provide a warp name!"); public Notice listPermission = Notice.chat("Permissions for warp {WARP}: {PERMISSIONS}"); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index 078a3becf..373bd9468 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -390,6 +390,7 @@ public static class PLWarpSection implements WarpSection { public Notice removePermission = Notice.chat("Usunięto uprawnienie {PERMISSION} z warpa {WARP}!"); public Notice noPermissionsProvided = Notice.chat("Nie podano żadnych uprawnień!"); public Notice permissionDoesNotExist = Notice.chat("Podane uprawnienie nie istnieje ({PERMISSION})!"); + public Notice permissionAlreadyExist = Notice.chat("Podane uprawnienie już istnieje ({PERMISSION})!"); public Notice noPermissionAssigned = Notice.chat("Ten warp nie ma przypisanych żadnych permisji"); public Notice missingWarpName = Notice.chat("Musisz podać nazwę warpu!"); public Notice listPermission = Notice.chat("Lista uprawnień dla warpa {WARP}: {PERMISSIONS}!"); From 95f8ed345f2fb6624cbcbc76168e4caf1db88730 Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 15:12:14 +0100 Subject: [PATCH 13/21] Follow mr. @Rollczi review. --- .../eternalcode/core/feature/warp/Warp.java | 2 + .../core/feature/warp/WarpService.java | 14 +++---- .../core/feature/warp/WarpImpl.java | 5 +++ .../core/feature/warp/WarpInventory.java | 4 +- .../core/feature/warp/WarpServiceImpl.java | 32 ++++----------- .../feature/warp/command/DelWarpCommand.java | 4 +- .../feature/warp/command/SetWarpCommand.java | 6 +-- .../feature/warp/command/WarpArgument.java | 8 +++- .../feature/warp/command/WarpCommand.java | 7 +++- .../WarpRemovePermissionCommand.java | 4 +- ...verEntry.java => WarpPermissionEntry.java} | 2 +- .../WarpPermissionMultiArgumentResolver.java | 20 ++++++---- .../WarpConfigRepresenter.java} | 9 +++-- .../{data => repository}/WarpDataConfig.java | 6 +-- .../WarpRepository.java} | 4 +- .../WarpRepositoryImpl.java} | 40 +++++++++---------- 16 files changed, 84 insertions(+), 83 deletions(-) rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/{WarpPermissionMultipleResolverEntry.java => WarpPermissionEntry.java} (59%) rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/{data/WarpDataConfigRepresenter.java => repository/WarpConfigRepresenter.java} (57%) rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/{data => repository}/WarpDataConfig.java (80%) rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/{data/WarpDataRepository.java => repository/WarpRepository.java} (85%) rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/{data/WarpDataRepositoryImpl.java => repository/WarpRepositoryImpl.java} (71%) diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java index c1cc16f45..93227722c 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java @@ -12,4 +12,6 @@ public interface Warp { List getPermissions(); + boolean hasPermission(String permission); + } diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java index b5e73bed0..52f583897 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java @@ -4,24 +4,22 @@ import java.util.Collection; import java.util.Optional; +import org.jetbrains.annotations.ApiStatus.Experimental; public interface WarpService { - Warp create(String name, Location location); + Warp createWarp(String name, Location location); - void delete(String warp); + void removeWarp(String warp); void addPermissions(String warp, String... permissions); + @Experimental void removePermission(String warp, String permission); - boolean exists(String name); - - boolean hasPermission(String warp, String permission); + boolean isExist(String name); Optional findWarp(String name); - Collection getAllNames(); - - boolean isEmpty(); + Collection getWarps(); } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java index a948e6100..483d85e3d 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java @@ -36,6 +36,11 @@ public List getPermissions() { return Collections.unmodifiableList(this.permissions); } + @Override + public boolean hasPermission(String permission) { + return this.permissions.contains(permission); + } + public void setPermissions(List permissions) { this.permissions = permissions; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java index 184caa653..297718c1e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java @@ -198,7 +198,7 @@ public void openInventory(Player player, Language language) { } public void addWarp(Warp warp) { - if (!this.warpManager.exists(warp.getName())) { + if (!this.warpManager.isExist(warp.getName())) { return; } @@ -243,7 +243,7 @@ public void addWarp(Warp warp) { public boolean removeWarp(String warpName) { - if (!this.warpManager.exists(warpName)) { + if (!this.warpManager.isExist(warpName)) { return false; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java index b5503eb87..3a2e955cf 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java @@ -2,7 +2,7 @@ import com.eternalcode.annotations.scan.feature.FeatureDocs; import com.eternalcode.commons.bukkit.position.PositionAdapter; -import com.eternalcode.core.feature.warp.data.WarpDataRepository; +import com.eternalcode.core.feature.warp.repository.WarpRepository; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import java.util.ArrayList; @@ -23,10 +23,10 @@ class WarpServiceImpl implements WarpService { private final Map warps = new ConcurrentHashMap<>(); - private final WarpDataRepository warpRepository; + private final WarpRepository warpRepository; @Inject - private WarpServiceImpl(WarpDataRepository warpRepository) { + private WarpServiceImpl(WarpRepository warpRepository) { this.warpRepository = warpRepository; warpRepository.getWarps().thenAcceptAsync(warps -> { @@ -37,7 +37,7 @@ private WarpServiceImpl(WarpDataRepository warpRepository) { } @Override - public Warp create(String name, Location location) { + public Warp createWarp(String name, Location location) { Warp warp = new WarpImpl(name, PositionAdapter.convert(location), new ArrayList<>()); this.warps.put(name, warp); @@ -47,7 +47,7 @@ public Warp create(String name, Location location) { } @Override - public void delete(String warp) { + public void removeWarp(String warp) { Warp remove = this.warps.remove(warp); if (remove == null) { @@ -108,33 +108,17 @@ private void modifyPermissions(String warpName, Consumer> modifier) } @Override - public boolean exists(String name) { + public boolean isExist(String name) { return this.warps.containsKey(name); } - @Override - public boolean hasPermission(String warpName, String permission) { - Warp warp = this.warps.get(warpName); - - if (warp == null) { - return false; - } - - return warp.getPermissions().contains(permission); - } - @Override public Optional findWarp(String name) { return Optional.ofNullable(this.warps.get(name)); } @Override - public Collection getAllNames() { - return Collections.unmodifiableCollection(this.warps.keySet()); - } - - @Override - public boolean isEmpty() { - return this.warps.isEmpty(); + public Collection getWarps() { + return Collections.unmodifiableCollection(this.warps.values()); } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java index 816d68aa9..d266bd9a0 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java @@ -37,7 +37,7 @@ void remove(@Context Player player, @Arg Warp warp) { } private void removeWarp(Player player, String name) { - if (!this.warpService.exists(name)) { + if (!this.warpService.isExist(name)) { this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().notExist()) @@ -47,7 +47,7 @@ private void removeWarp(Player player, String name) { return; } - this.warpService.delete(name); + this.warpService.removeWarp(name); this.warpInventory.removeWarp(name); this.noticeService.create() diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java index a11db47a4..1bf3171d7 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java @@ -44,7 +44,7 @@ void add(@Context Player player, @Arg String warpName) { } private void createWarp(Player player, String warp, UUID uniqueId) { - if (this.warpService.exists(warp)) { + if (this.warpService.isExist(warp)) { this.noticeService.create() .player(uniqueId) .notice(translation -> translation.warp().warpAlreadyExists()) @@ -54,7 +54,7 @@ private void createWarp(Player player, String warp, UUID uniqueId) { return; } - Warp createdWarp = this.warpService.create(warp, player.getLocation()); + Warp createdWarp = this.warpService.createWarp(warp, player.getLocation()); this.noticeService.create() .player(uniqueId) @@ -63,7 +63,7 @@ private void createWarp(Player player, String warp, UUID uniqueId) { .send(); if (this.config.warp.autoAddNewWarps) { - if (this.warpService.getAllNames().size() <= MAX_WARPS_IN_GUI) { + if (this.warpService.getWarps().size() <= MAX_WARPS_IN_GUI) { this.warpInventory.addWarp(createdWarp); this.noticeService.create() diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java index 40526f207..51fe1f3fd 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java @@ -17,6 +17,7 @@ import dev.rollczi.litecommands.suggestion.SuggestionContext; import dev.rollczi.litecommands.suggestion.SuggestionResult; import java.util.Optional; +import java.util.stream.Collectors; import org.bukkit.command.CommandSender; @LiteArgument(type = Warp.class) @@ -58,8 +59,11 @@ public SuggestionResult suggest( Argument argument, SuggestionContext context ) { - return this.warpService.getAllNames().stream() - .collect(SuggestionResult.collector()); + return SuggestionResult.of( + this.warpService.getWarps().stream() + .map(Warp::getName) + .collect(Collectors.toList()) + ); } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java index bf5c480c5..bc8c860cf 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java @@ -14,6 +14,7 @@ import dev.rollczi.litecommands.annotations.context.Context; import dev.rollczi.litecommands.annotations.execute.Execute; import dev.rollczi.litecommands.annotations.permission.Permission; +import java.util.List; import org.bukkit.entity.Player; @RootCommand @@ -45,16 +46,18 @@ class WarpCommand { @DescriptionDocs(description = "Open warp inventory, optionally you can disable this feature in config, if feature is disabled eternalcore will show all available warps") void warp(@Context Player player, @Context User user) { if (!this.config.warp.inventoryEnabled) { + List list = this.warpService.getWarps().stream().map(Warp::getName).toList(); + this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().available()) - .placeholder("{WARPS}", String.join(", ", this.warpService.getAllNames())) + .placeholder("{WARPS}", String.join(this.config.format.separator, list)) .send(); return; } - if (!this.warpService.isEmpty()) { + if (this.warpService.getWarps().isEmpty()) { this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().noWarps()) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java index 852c87be7..6fb43e466 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java @@ -2,7 +2,7 @@ import com.eternalcode.core.feature.warp.Warp; import com.eternalcode.core.feature.warp.WarpService; -import com.eternalcode.core.feature.warp.command.permission.argument.WarpPermissionMultipleResolverEntry; +import com.eternalcode.core.feature.warp.command.permission.argument.WarpPermissionEntry; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.notice.NoticeService; import dev.rollczi.litecommands.annotations.argument.Arg; @@ -28,7 +28,7 @@ public WarpRemovePermissionCommand(WarpService warpService, NoticeService notice @Execute void removePermission( @Context Player player, - @Arg WarpPermissionMultipleResolverEntry entry + @Arg WarpPermissionEntry entry ) { Warp warp = entry.warp(); String permission = entry.permission(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultipleResolverEntry.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionEntry.java similarity index 59% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultipleResolverEntry.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionEntry.java index a0e3beb6d..46e26fef8 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultipleResolverEntry.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionEntry.java @@ -2,5 +2,5 @@ import com.eternalcode.core.feature.warp.Warp; -public record WarpPermissionMultipleResolverEntry(Warp warp, String permission) { +public record WarpPermissionEntry(Warp warp, String permission) { } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java index f2eab3979..dea278e96 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java @@ -21,9 +21,9 @@ import java.util.Optional; import org.bukkit.command.CommandSender; -@LiteArgument(type = WarpPermissionMultipleResolverEntry.class) +@LiteArgument(type = WarpPermissionEntry.class) public class WarpPermissionMultiArgumentResolver - implements MultipleArgumentResolver { + implements MultipleArgumentResolver { private static final String WARP_PLACEHOLDER_PREFIX = "{WARP}"; private static final String PERMISSION_PLACEHOLDER_PREFIX = "{PERMISSION}"; @@ -47,9 +47,9 @@ public WarpPermissionMultiArgumentResolver( } @Override - public ParseResult parse( + public ParseResult parse( Invocation invocation, - Argument argument, + Argument argument, RawInput rawInput ) { Viewer viewer = this.viewerService.any(invocation.sender()); @@ -94,25 +94,29 @@ public ParseResult parse( String permission = rawInput.next(); - return ParseResult.success(new WarpPermissionMultipleResolverEntry(warp.get(), permission)); + return ParseResult.success(new WarpPermissionEntry(warp.get(), permission)); } @Override - public Range getRange(Argument argument) { + public Range getRange(Argument argument) { return Range.of(2); } @Override public SuggestionResult suggest( Invocation invocation, - Argument argument, + Argument argument, SuggestionContext context ) { Suggestion current = context.getCurrent(); int index = current.lengthMultilevel(); if (index == 1) { - return SuggestionResult.of(this.warpService.getAllNames()); + return SuggestionResult.of( + this.warpService.getWarps().stream() + .map(Warp::getName) + .toList() + ); } if (index == 2) { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfigRepresenter.java similarity index 57% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfigRepresenter.java index c37ae603c..2b7fc666f 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfigRepresenter.java @@ -1,18 +1,19 @@ -package com.eternalcode.core.feature.warp.data; +package com.eternalcode.core.feature.warp.repository; import com.eternalcode.commons.bukkit.position.Position; import java.util.List; import net.dzikoysk.cdn.entity.Contextual; @Contextual -public class WarpDataConfigRepresenter { +class WarpConfigRepresenter { + public Position position; public List permissions; - public WarpDataConfigRepresenter() { + WarpConfigRepresenter() { } - public WarpDataConfigRepresenter(Position position, List permissions) { + public WarpConfigRepresenter(Position position, List permissions) { this.position = position; this.permissions = permissions; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfig.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java similarity index 80% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfig.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java index 5e13c12c0..366ebd8dd 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfig.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java @@ -1,4 +1,4 @@ -package com.eternalcode.core.feature.warp.data; +package com.eternalcode.core.feature.warp.repository; import com.eternalcode.core.configuration.ReloadableConfig; import com.eternalcode.core.injector.annotations.component.ConfigurationFile; @@ -11,13 +11,13 @@ import net.dzikoysk.cdn.source.Source; @ConfigurationFile -public class WarpDataConfig implements ReloadableConfig { +class WarpDataConfig implements ReloadableConfig { @Exclude public static final String WARP_DATA_FILE_PATH = "data" + File.separator + "warps.yml"; @Description({"# Warps data", "# These are warp locations, for your own safety, please don't touch it."}) - public Map warps = new HashMap<>(); + public Map warps = new HashMap<>(); @Override public Resource resource(File folder) { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepository.java similarity index 85% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepository.java index 11a6bb8a4..67f39ce9c 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepository.java @@ -1,11 +1,11 @@ -package com.eternalcode.core.feature.warp.data; +package com.eternalcode.core.feature.warp.repository; import com.eternalcode.core.feature.warp.Warp; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; -public interface WarpDataRepository { +public interface WarpRepository { CompletableFuture addWarp(Warp warp); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java similarity index 71% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java index 854af27ee..53f2e3fc2 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.eternalcode.core.feature.warp.data; +package com.eternalcode.core.feature.warp.repository; import com.eternalcode.commons.bukkit.position.PositionAdapter; import com.eternalcode.core.configuration.ConfigurationManager; @@ -6,7 +6,7 @@ import com.eternalcode.core.feature.warp.Warp; import com.eternalcode.core.feature.warp.WarpImpl; import com.eternalcode.core.injector.annotations.Inject; -import com.eternalcode.core.injector.annotations.component.Service; +import com.eternalcode.core.injector.annotations.component.Repository; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -16,15 +16,15 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -@Service -public class WarpDataRepositoryImpl implements WarpDataRepository { +@Repository +class WarpRepositoryImpl implements WarpRepository { private final LocationsConfiguration locationsConfiguration; private final WarpDataConfig warpDataConfig; private final ConfigurationManager configurationManager; @Inject - WarpDataRepositoryImpl( + WarpRepositoryImpl( ConfigurationManager configurationManager, LocationsConfiguration locationsConfiguration, WarpDataConfig warpDataConfig @@ -39,12 +39,12 @@ public class WarpDataRepositoryImpl implements WarpDataRepository { @Override public CompletableFuture addWarp(Warp warp) { return CompletableFuture.runAsync(() -> { - WarpDataConfigRepresenter warpDataConfigRepresenter = new WarpDataConfigRepresenter( + WarpConfigRepresenter warpConfigRepresenter = new WarpConfigRepresenter( PositionAdapter.convert(warp.getLocation()), warp.getPermissions() ); - this.edit(warps -> warps.put(warp.getName(), warpDataConfigRepresenter)); + this.edit(warps -> warps.put(warp.getName(), warpConfigRepresenter)); }); } @@ -56,31 +56,31 @@ public CompletableFuture removeWarp(String warp) { @Override public CompletableFuture addPermissions(String warp, String... permissions) { return CompletableFuture.runAsync(() -> this.edit(warps -> { - WarpDataConfigRepresenter warpDataConfigRepresenter = warps.get(warp); - if (warpDataConfigRepresenter == null) { + WarpConfigRepresenter warpConfigRepresenter = warps.get(warp); + if (warpConfigRepresenter == null) { return; } - warpDataConfigRepresenter.permissions.addAll(List.of(permissions)); + warpConfigRepresenter.permissions.addAll(List.of(permissions)); })); } @Override public CompletableFuture removePermission(String warp, String permission) { return CompletableFuture.runAsync(() -> this.edit(warps -> { - WarpDataConfigRepresenter warpDataConfigRepresenter = warps.get(warp); + WarpConfigRepresenter warpConfigRepresenter = warps.get(warp); - if (warpDataConfigRepresenter == null) { + if (warpConfigRepresenter == null) { return; } - warpDataConfigRepresenter.permissions.remove(permission); + warpConfigRepresenter.permissions.remove(permission); })); } - private void edit(Consumer> editor) { + private void edit(Consumer> editor) { synchronized (warpDataConfig.warps) { - Map warps = new HashMap<>(this.warpDataConfig.warps); + Map warps = new HashMap<>(this.warpDataConfig.warps); editor.accept(warps); this.warpDataConfig.warps.putAll(warps); this.configurationManager.save(this.warpDataConfig); @@ -90,17 +90,17 @@ private void edit(Consumer> editor) { @Override public CompletableFuture> getWarp(String name) { return CompletableFuture.completedFuture(Optional.ofNullable(this.warpDataConfig.warps.get(name)) - .map(warpDataConfigRepresenter -> new WarpImpl( + .map(warpConfigRepresenter -> new WarpImpl( name, - warpDataConfigRepresenter.position, - warpDataConfigRepresenter.permissions))); + warpConfigRepresenter.position, + warpConfigRepresenter.permissions))); } @Override public CompletableFuture> getWarps() { return CompletableFuture.completedFuture(this.warpDataConfig.warps.entrySet().stream() .map(warpConfigEntry -> { - WarpDataConfigRepresenter warpContextual = warpConfigEntry.getValue(); + WarpConfigRepresenter warpContextual = warpConfigEntry.getValue(); return new WarpImpl(warpConfigEntry.getKey(), warpContextual.position, warpContextual.permissions); }) .collect(Collectors.toList())); @@ -116,7 +116,7 @@ private void migrateWarps() { .stream() .collect(Collectors.toMap( Map.Entry::getKey, entry -> - new WarpDataConfigRepresenter(entry.getValue(), new ArrayList<>())) + new WarpConfigRepresenter(entry.getValue(), new ArrayList<>())) ) )); From 60b4c1112730702db2b61728c472e8947bd340de Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 15:20:15 +0100 Subject: [PATCH 14/21] Follow mr. @Rollczi review. v2 --- .../WarpPermissionMultiArgumentResolver.java | 25 +++---------------- .../core/translation/Translation.java | 5 ++-- .../implementation/ENTranslation.java | 5 ++-- .../implementation/PLTranslation.java | 4 +-- 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java index dea278e96..5d66b658f 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java @@ -1,6 +1,5 @@ package com.eternalcode.core.feature.warp.command.permission.argument; -import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.feature.warp.Warp; import com.eternalcode.core.feature.warp.WarpService; import com.eternalcode.core.injector.annotations.Inject; @@ -26,21 +25,16 @@ public class WarpPermissionMultiArgumentResolver implements MultipleArgumentResolver { private static final String WARP_PLACEHOLDER_PREFIX = "{WARP}"; - private static final String PERMISSION_PLACEHOLDER_PREFIX = "{PERMISSION}"; - - private final PluginConfiguration config; private final WarpService warpService; private final NoticeService noticeService; private final ViewerService viewerService; @Inject public WarpPermissionMultiArgumentResolver( - PluginConfiguration config, WarpService warpService, NoticeService noticeService, ViewerService viewerService ) { - this.config = config; this.warpService = warpService; this.noticeService = noticeService; this.viewerService = viewerService; @@ -56,7 +50,7 @@ public ParseResult parse( if (!rawInput.hasNext()) { return ParseResult.failure(this.noticeService.create() - .notice(translation -> translation.warp().missingWarpName()) + .notice(translation -> translation.warp().missingWarpArgument()) .viewer(viewer) ); } @@ -74,26 +68,13 @@ public ParseResult parse( } if (!rawInput.hasNext()) { - Collection permissions = warp.get().getPermissions(); - - if (permissions.isEmpty()) { - return ParseResult.failure(this.noticeService.create() - .notice(translation -> translation.warp().noPermissionAssigned()) - .placeholder(WARP_PLACEHOLDER_PREFIX, warpName) - .viewer(viewer) - ); - } - return ParseResult.failure(this.noticeService.create() - .notice(translation -> translation.warp().listPermission()) - .placeholder(WARP_PLACEHOLDER_PREFIX, warpName) - .placeholder(PERMISSION_PLACEHOLDER_PREFIX, String.join(this.config.format.separator, permissions)) + .notice(translation -> translation.warp().missingPermissionArgument()) .viewer(viewer) ); } String permission = rawInput.next(); - return ParseResult.success(new WarpPermissionEntry(warp.get(), permission)); } @@ -120,7 +101,7 @@ public SuggestionResult suggest( } if (index == 2) { - String warpName = current.multilevelList().get(0); + String warpName = current.multilevelList().getFirst(); Optional warpOptional = this.warpService.findWarp(warpName); if (warpOptional.isEmpty()) { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java index 2dbc258c9..0fbd21922 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java @@ -158,9 +158,8 @@ interface WarpSection { Notice permissionDoesNotExist(); Notice permissionAlreadyExist(); Notice noPermissionsProvided(); - Notice noPermissionAssigned(); - Notice missingWarpName(); - Notice listPermission(); + Notice missingWarpArgument(); + Notice missingPermissionArgument(); WarpInventorySection warpInventory(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java index 28ff3db8e..3a7446ce3 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java @@ -389,8 +389,9 @@ public static class ENWarpSection implements WarpSection { public Notice permissionDoesNotExist = Notice.chat("Permission {PERMISSION} doesn't exist!"); public Notice permissionAlreadyExist = Notice.chat("Permission {PERMISSION} already exists!"); public Notice noPermissionAssigned = Notice.chat("There are no permissions assigned to this warp!"); - public Notice missingWarpName = Notice.chat("You must provide a warp name!"); - public Notice listPermission = Notice.chat("Permissions for warp {WARP}: {PERMISSIONS}"); + public Notice missingWarpArgument = Notice.chat("You must provide a warp name!"); + public Notice missingPermissionArgument = Notice.chat("You must provide a permission!"); + @Description({" ", "# {WARPS} - List of warps (separated by commas)"}) public Notice available = Notice.chat("Available warps: {WARPS}"); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index 373bd9468..c1cfa5529 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -392,8 +392,8 @@ public static class PLWarpSection implements WarpSection { public Notice permissionDoesNotExist = Notice.chat("Podane uprawnienie nie istnieje ({PERMISSION})!"); public Notice permissionAlreadyExist = Notice.chat("Podane uprawnienie już istnieje ({PERMISSION})!"); public Notice noPermissionAssigned = Notice.chat("Ten warp nie ma przypisanych żadnych permisji"); - public Notice missingWarpName = Notice.chat("Musisz podać nazwę warpu!"); - public Notice listPermission = Notice.chat("Lista uprawnień dla warpa {WARP}: {PERMISSIONS}!"); + public Notice missingWarpArgument = Notice.chat("Musisz podać nazwę warpu!"); + public Notice missingPermissionArgument = Notice.chat("Musisz podać uprawnienie!"); @Description({" ", "# {WARPS} - Lista dostępnych warpów"}) public Notice available = Notice.chat("Dostepne warpy: {WARPS}!"); From f86cc47be01b839c20a52de4d4e547dc969fed95 Mon Sep 17 00:00:00 2001 From: Rollczi Date: Sun, 12 Jan 2025 15:22:38 +0100 Subject: [PATCH 15/21] Fix synchronized --- .../core/feature/warp/WarpService.java | 4 +- .../core/feature/warp/WarpImpl.java | 4 - .../core/feature/warp/WarpServiceImpl.java | 42 ++----- .../WarpRemovePermissionCommand.java | 2 +- .../warp/data/WarpDataConfigRepresenter.java | 2 +- .../feature/warp/data/WarpDataRepository.java | 6 +- .../warp/data/WarpDataRepositoryImpl.java | 116 ++++++++---------- 7 files changed, 71 insertions(+), 105 deletions(-) diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java index b5e73bed0..1be583017 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java @@ -11,9 +11,9 @@ public interface WarpService { void delete(String warp); - void addPermissions(String warp, String... permissions); + Warp addPermissions(String warp, String... permissions); - void removePermission(String warp, String permission); + Warp removePermissions(String warp, String... permissions); boolean exists(String name); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java index a948e6100..88f8afd9e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java @@ -35,8 +35,4 @@ public Location getLocation() { public List getPermissions() { return Collections.unmodifiableList(this.permissions); } - - public void setPermissions(List permissions) { - this.permissions = permissions; - } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java index b5503eb87..881e5fe20 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java @@ -41,7 +41,7 @@ public Warp create(String name, Location location) { Warp warp = new WarpImpl(name, PositionAdapter.convert(location), new ArrayList<>()); this.warps.put(name, warp); - this.warpRepository.addWarp(warp); + this.warpRepository.saveWarp(warp); return warp; } @@ -49,7 +49,6 @@ public Warp create(String name, Location location) { @Override public void delete(String warp) { Warp remove = this.warps.remove(warp); - if (remove == null) { return; } @@ -58,41 +57,23 @@ public void delete(String warp) { } @Override - public void addPermissions(String warpName, String... permissions) { - Warp warp = this.warps.get(warpName); - - if (warp == null) { - return; - } - - if (permissions == null) { - return; - } - - List updatedPermissions = new ArrayList<>(warp.getPermissions()); - updatedPermissions.addAll(List.of(permissions)); - - this.modifyPermissions(warpName, perms -> perms.addAll(List.of(permissions))); - this.warpRepository.addPermissions(warpName, permissions); + public Warp addPermissions(String warpName, String... permissions) { + Warp warp = this.modifyPermissions(warpName, perms -> perms.addAll(List.of(permissions))); + this.warpRepository.saveWarp(warp); + return warp; } @Override - public void removePermission(String warpName, String permission) { - Warp warp = this.warps.get(warpName); - - if (warp == null) { - return; - } - - this.modifyPermissions(warpName, perms -> perms.remove(permission)); - this.warpRepository.removePermission(warpName, permission); + public Warp removePermissions(String warpName, String... permissions) { + Warp warp = this.modifyPermissions(warpName, perms -> perms.addAll(List.of(permissions))); + this.warpRepository.saveWarp(warp); + return warp; } - private void modifyPermissions(String warpName, Consumer> modifier) { + private Warp modifyPermissions(String warpName, Consumer> modifier) { Warp warp = this.warps.get(warpName); - if (warp == null) { - return; + throw new IllegalArgumentException("Warp " + warpName + " does not exist"); } List updatedPermissions = new ArrayList<>(warp.getPermissions()); @@ -105,6 +86,7 @@ private void modifyPermissions(String warpName, Consumer> modifier) ); this.warps.put(warpName, updatedWarp); + return updatedWarp; } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java index 852c87be7..cd6cce687 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java @@ -43,7 +43,7 @@ void removePermission( return; } - this.warpService.removePermission(warp.getName(), permission); + this.warpService.removePermissions(warp.getName(), permission); this.noticeService.create() .placeholder("{WARP}", warp.getName()) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java index c37ae603c..5ce868f1b 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataConfigRepresenter.java @@ -5,7 +5,7 @@ import net.dzikoysk.cdn.entity.Contextual; @Contextual -public class WarpDataConfigRepresenter { +class WarpDataConfigRepresenter { public Position position; public List permissions; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java index 11a6bb8a4..44e976906 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepository.java @@ -7,14 +7,10 @@ public interface WarpDataRepository { - CompletableFuture addWarp(Warp warp); + CompletableFuture saveWarp(Warp warp); CompletableFuture removeWarp(String warp); - CompletableFuture addPermissions(String warp, String... permissions); - - CompletableFuture removePermission(String warp, String permission); - CompletableFuture> getWarp(String name); CompletableFuture> getWarps(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java index 854af27ee..911d40eb0 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/data/WarpDataRepositoryImpl.java @@ -1,6 +1,7 @@ package com.eternalcode.core.feature.warp.data; import com.eternalcode.commons.bukkit.position.PositionAdapter; +import com.eternalcode.commons.scheduler.Scheduler; import com.eternalcode.core.configuration.ConfigurationManager; import com.eternalcode.core.configuration.implementation.LocationsConfiguration; import com.eternalcode.core.feature.warp.Warp; @@ -14,91 +15,61 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; +import java.util.function.Function; import java.util.stream.Collectors; @Service public class WarpDataRepositoryImpl implements WarpDataRepository { + private static final Object READ_WRITE_LOCK = new Object(); + private final LocationsConfiguration locationsConfiguration; private final WarpDataConfig warpDataConfig; private final ConfigurationManager configurationManager; + private final Scheduler scheduler; @Inject WarpDataRepositoryImpl( ConfigurationManager configurationManager, LocationsConfiguration locationsConfiguration, - WarpDataConfig warpDataConfig + WarpDataConfig warpDataConfig, Scheduler scheduler ) { this.locationsConfiguration = locationsConfiguration; this.configurationManager = configurationManager; this.warpDataConfig = warpDataConfig; + this.scheduler = scheduler; this.migrateWarps(); } @Override - public CompletableFuture addWarp(Warp warp) { - return CompletableFuture.runAsync(() -> { - WarpDataConfigRepresenter warpDataConfigRepresenter = new WarpDataConfigRepresenter( - PositionAdapter.convert(warp.getLocation()), - warp.getPermissions() - ); - - this.edit(warps -> warps.put(warp.getName(), warpDataConfigRepresenter)); - }); - } - - @Override - public CompletableFuture removeWarp(String warp) { - return CompletableFuture.runAsync(() -> this.edit(warps -> warps.remove(warp))); - } - - @Override - public CompletableFuture addPermissions(String warp, String... permissions) { - return CompletableFuture.runAsync(() -> this.edit(warps -> { - WarpDataConfigRepresenter warpDataConfigRepresenter = warps.get(warp); - if (warpDataConfigRepresenter == null) { - return; - } + public CompletableFuture saveWarp(Warp warp) { + WarpDataConfigRepresenter warpDataConfigRepresenter = new WarpDataConfigRepresenter( + PositionAdapter.convert(warp.getLocation()), + warp.getPermissions() + ); - warpDataConfigRepresenter.permissions.addAll(List.of(permissions)); - })); + return this.transactionalRun(warps -> warps.put(warp.getName(), warpDataConfigRepresenter)); } @Override - public CompletableFuture removePermission(String warp, String permission) { - return CompletableFuture.runAsync(() -> this.edit(warps -> { - WarpDataConfigRepresenter warpDataConfigRepresenter = warps.get(warp); - - if (warpDataConfigRepresenter == null) { - return; - } - - warpDataConfigRepresenter.permissions.remove(permission); - })); - } - - private void edit(Consumer> editor) { - synchronized (warpDataConfig.warps) { - Map warps = new HashMap<>(this.warpDataConfig.warps); - editor.accept(warps); - this.warpDataConfig.warps.putAll(warps); - this.configurationManager.save(this.warpDataConfig); - } + public CompletableFuture removeWarp(String warp) { + return this.transactionalRun(warps -> warps.remove(warp)); } @Override public CompletableFuture> getWarp(String name) { - return CompletableFuture.completedFuture(Optional.ofNullable(this.warpDataConfig.warps.get(name)) + return transactionalSupply(warps -> Optional.ofNullable(this.warpDataConfig.warps.get(name)) .map(warpDataConfigRepresenter -> new WarpImpl( name, warpDataConfigRepresenter.position, - warpDataConfigRepresenter.permissions))); + warpDataConfigRepresenter.permissions) + )); } @Override public CompletableFuture> getWarps() { - return CompletableFuture.completedFuture(this.warpDataConfig.warps.entrySet().stream() + return transactionalSupply(warps -> warps.entrySet().stream() .map(warpConfigEntry -> { WarpDataConfigRepresenter warpContextual = warpConfigEntry.getValue(); return new WarpImpl(warpConfigEntry.getKey(), warpContextual.position, warpContextual.permissions); @@ -107,21 +78,42 @@ public CompletableFuture> getWarps() { } private void migrateWarps() { - if (this.locationsConfiguration.warps.isEmpty()) { - return; + synchronized (READ_WRITE_LOCK) { + if (this.locationsConfiguration.warps.isEmpty()) { + return; + } + + this.transactionalRun(warps -> warps.putAll(this.locationsConfiguration.warps + .entrySet() + .stream() + .collect(Collectors.toMap( + entry -> entry.getKey(), + entry -> new WarpDataConfigRepresenter(entry.getValue(), new ArrayList<>())) + ) + )); + + this.locationsConfiguration.warps.clear(); + this.configurationManager.save(this.locationsConfiguration); } + } - this.edit(warps -> warps.putAll(this.locationsConfiguration.warps - .entrySet() - .stream() - .collect(Collectors.toMap( - Map.Entry::getKey, entry -> - new WarpDataConfigRepresenter(entry.getValue(), new ArrayList<>())) - ) - )); - - this.locationsConfiguration.warps.clear(); - this.configurationManager.save(this.locationsConfiguration); - this.configurationManager.save(this.warpDataConfig); + private CompletableFuture transactionalRun(Consumer> editor) { + return transactionalSupply(warps -> { + editor.accept(warps); + return null; + }); } + + private CompletableFuture transactionalSupply(Function, T> editor) { + return scheduler.completeAsync(() -> { + synchronized (READ_WRITE_LOCK) { + Map warps = new HashMap<>(this.warpDataConfig.warps); + T result = editor.apply(warps); + this.warpDataConfig.warps.putAll(warps); + this.configurationManager.save(this.warpDataConfig); + return result; + } + }); + } + } From e68afcc799047133c3f512306d6223ffadcca824 Mon Sep 17 00:00:00 2001 From: Rollczi Date: Sun, 12 Jan 2025 15:27:07 +0100 Subject: [PATCH 16/21] Fix merge --- .../java/com/eternalcode/core/feature/warp/WarpImpl.java | 3 +-- .../core/feature/warp/repository/WarpRepositoryImpl.java | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java index bb0f9f69f..bb35686d8 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java @@ -8,12 +8,11 @@ import java.util.Collections; import java.util.List; -@SuppressWarnings("LombokSetterMayBeUsed") public class WarpImpl implements Warp { private final String name; private final Position position; - private List permissions; + private final List permissions; public WarpImpl(String name, Position position, List permissions) { this.name = name; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java index 9cfafdc86..8135f59e0 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java @@ -97,17 +97,17 @@ private void migrateWarps() { } } - private CompletableFuture transactionalRun(Consumer> editor) { + private CompletableFuture transactionalRun(Consumer> editor) { return transactionalSupply(warps -> { editor.accept(warps); return null; }); } - private CompletableFuture transactionalSupply(Function, T> editor) { + private CompletableFuture transactionalSupply(Function, T> editor) { return scheduler.completeAsync(() -> { synchronized (READ_WRITE_LOCK) { - Map warps = new HashMap<>(this.warpDataConfig.warps); + Map warps = new HashMap<>(this.warpDataConfig.warps); T result = editor.apply(warps); this.warpDataConfig.warps.putAll(warps); this.configurationManager.save(this.warpDataConfig); From a67693cc410fe95b25cc4c104c9e6f6b5934c3ca Mon Sep 17 00:00:00 2001 From: Rollczi Date: Sun, 12 Jan 2025 15:50:05 +0100 Subject: [PATCH 17/21] Fix events life cycle --- .../warp/event/PreWarpTeleportEvent.java | 28 ++++++++- .../feature/warp/event/WarpTeleportEvent.java | 10 ++- .../warp/WarpPermissionController.java | 63 ------------------- .../core/feature/warp/WarpServiceImpl.java | 2 +- .../feature/warp/WarpTeleportService.java | 25 ++++---- .../feature/warp/command/WarpCommand.java | 25 ++++++++ .../repository/WarpConfigRepresenter.java | 19 ------ .../warp/repository/WarpDataConfig.java | 19 +++++- .../warp/repository/WarpRepositoryImpl.java | 20 +++--- 9 files changed, 103 insertions(+), 108 deletions(-) delete mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java delete mode 100644 eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfigRepresenter.java diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/PreWarpTeleportEvent.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/PreWarpTeleportEvent.java index ebdfe99e1..e8a37c916 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/PreWarpTeleportEvent.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/PreWarpTeleportEvent.java @@ -1,10 +1,14 @@ package com.eternalcode.core.feature.warp.event; import com.eternalcode.core.feature.warp.Warp; +import com.google.common.base.Preconditions; +import java.time.Duration; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.Nullable; /** * Called before teleportation to warp. @@ -16,12 +20,15 @@ public class PreWarpTeleportEvent extends Event implements Cancellable { private final Player player; private Warp warp; private boolean cancelled; + private Duration teleportTime; + private @Nullable Location destination; - public PreWarpTeleportEvent(Player player, Warp warp) { + public PreWarpTeleportEvent(Player player, Warp warp, Duration teleportTime) { super(false); this.player = player; this.warp = warp; + this.teleportTime = teleportTime; } public Player getPlayer() { @@ -33,9 +40,28 @@ public Warp getWarp() { } public void setWarp(Warp warp) { + Preconditions.checkNotNull(warp, "Warp cannot be null"); this.warp = warp; } + public Duration getTeleportTime() { + return this.teleportTime; + } + + public void setTeleportTime(Duration teleportTime) { + Preconditions.checkNotNull(teleportTime, "Teleport time cannot be null"); + this.teleportTime = teleportTime; + } + + public Location getDestination() { + return this.destination != null ? this.destination : this.warp.getLocation(); + } + + public void setDestination(Location destination) { + Preconditions.checkNotNull(destination, "Destination cannot be null"); + this.destination = destination; + } + @Override public boolean isCancelled() { return this.cancelled; diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/WarpTeleportEvent.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/WarpTeleportEvent.java index c323bc037..65fc77cda 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/WarpTeleportEvent.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/WarpTeleportEvent.java @@ -1,8 +1,8 @@ package com.eternalcode.core.feature.warp.event; import com.eternalcode.core.feature.warp.Warp; +import org.bukkit.Location; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -15,12 +15,14 @@ public class WarpTeleportEvent extends Event { private final Player player; private final Warp warp; + private final Location destination; - public WarpTeleportEvent(Player player, Warp warp) { + public WarpTeleportEvent(Player player, Warp warp, Location destination) { super(false); this.player = player; this.warp = warp; + this.destination = destination; } public Player getPlayer() { @@ -31,6 +33,10 @@ public Warp getWarp() { return this.warp; } + public Location getDestination() { + return this.destination; + } + @Override public HandlerList getHandlers() { return HANDLER_LIST; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java deleted file mode 100644 index 8f39392eb..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.eternalcode.core.feature.warp; - -import com.eternalcode.annotations.scan.feature.FeatureDocs; -import com.eternalcode.core.configuration.implementation.PluginConfiguration; -import com.eternalcode.core.feature.warp.event.PreWarpTeleportEvent; -import com.eternalcode.core.injector.annotations.Inject; -import com.eternalcode.core.injector.annotations.component.Controller; -import com.eternalcode.core.notice.NoticeService; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -@FeatureDocs( - description = "Check if a player has permission to use a specific warp", - name = "Warp permission" -) -@Controller -public class WarpPermissionController implements Listener { - - private final NoticeService noticeService; - private final PluginConfiguration config; - - @Inject - public WarpPermissionController(NoticeService noticeService, PluginConfiguration config) { - this.noticeService = noticeService; - this.config = config; - } - - @EventHandler - void onWarpPreTeleportation(PreWarpTeleportEvent event) { - Player player = event.getPlayer(); - UUID uniqueId = player.getUniqueId(); - Warp warp = event.getWarp(); - - this.checkWarpPermission(event, warp, player, uniqueId); - } - - private void checkWarpPermission(PreWarpTeleportEvent event, Warp warp, Player player, UUID uniqueId) { - List permissions = warp.getPermissions(); - Optional isPlayerAllowedToUseWarp = permissions - .stream() - .filter(player::hasPermission) - .findAny(); - - if (isPlayerAllowedToUseWarp.isPresent() || permissions.isEmpty()) { - return; - } - - event.setCancelled(true); - - this.noticeService.create() - .player(uniqueId) - .placeholder("{WARP}", warp.getName()) - .placeholder("{PERMISSIONS}", String.join(this.config.format.separator, permissions)) - .notice(translation -> translation.warp().noPermission()) - .send(); - } - -} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java index 7ce6a032c..5011d6564 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java @@ -65,7 +65,7 @@ public Warp addPermissions(String warpName, String... permissions) { @Override public Warp removePermissions(String warpName, String... permissions) { - Warp warp = this.modifyPermissions(warpName, perms -> perms.addAll(List.of(permissions))); + Warp warp = this.modifyPermissions(warpName, perms -> perms.removeAll(List.of(permissions))); this.warpRepository.saveWarp(warp); return warp; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpTeleportService.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpTeleportService.java index 5c388d4d7..080fdd947 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpTeleportService.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpTeleportService.java @@ -12,6 +12,7 @@ import com.eternalcode.core.injector.annotations.component.Service; import java.time.Duration; import java.util.UUID; +import org.bukkit.Location; import org.bukkit.entity.Player; @Service @@ -35,29 +36,31 @@ public WarpTeleportService( } public void teleport(Player player, Warp warp) { - PreWarpTeleportEvent pre = this.eventCaller.callEvent(new PreWarpTeleportEvent(player, warp)); + Duration teleportTime = player.hasPermission(WARP_BYPASS) + ? Duration.ZERO + : this.pluginConfiguration.warp.teleportTimeToWarp; + + PreWarpTeleportEvent pre = this.eventCaller.callEvent(new PreWarpTeleportEvent(player, warp, teleportTime)); if (pre.isCancelled()) { return; } - Duration teleportTime = player.hasPermission(WARP_BYPASS) - ? Duration.ZERO - : this.pluginConfiguration.warp.teleportTimeToWarp; - Warp destinationWarp = pre.getWarp(); + Location destination = pre.getDestination(); + Position destinationLocation = PositionAdapter.convert(destination); Position playerLocation = PositionAdapter.convert(player.getLocation()); - Position warpLocation = PositionAdapter.convert(destinationWarp.getLocation()); UUID uniqueId = player.getUniqueId(); - WarpTeleportEvent post = new WarpTeleportEvent(player, destinationWarp); - Teleport teleport = this.teleportTaskService.createTeleport( uniqueId, playerLocation, - warpLocation, - teleportTime + destinationLocation, + pre.getTeleportTime() ); - teleport.getResult().whenComplete((result, throwable) -> this.eventCaller.callEvent(post)); + + teleport.getResult().whenComplete((result, throwable) -> { + this.eventCaller.callEvent(new WarpTeleportEvent(player, destinationWarp, destination)); + }); } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java index bc8c860cf..e0503e0ca 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java @@ -6,6 +6,7 @@ import com.eternalcode.core.feature.warp.WarpInventory; import com.eternalcode.core.feature.warp.WarpService; import com.eternalcode.core.feature.warp.WarpTeleportService; +import com.eternalcode.core.feature.warp.event.PreWarpTeleportEvent; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.notice.NoticeService; import com.eternalcode.core.user.User; @@ -15,6 +16,8 @@ import dev.rollczi.litecommands.annotations.execute.Execute; import dev.rollczi.litecommands.annotations.permission.Permission; import java.util.List; +import java.util.Optional; +import java.util.UUID; import org.bukkit.entity.Player; @RootCommand @@ -72,6 +75,28 @@ void warp(@Context Player player, @Context User user) { @Execute(name = "warp") @DescriptionDocs(description = "Teleport to warp, if player has permission eternalcore.warp.bypass teleport will be instant", arguments = "") void warp(@Context Player player, @Arg Warp warp) { + if (!this.hasPermission(player, warp)) { + this.noticeService.create() + .player(player.getUniqueId()) + .placeholder("{WARP}", warp.getName()) + .placeholder("{PERMISSIONS}", String.join(this.config.format.separator, warp.getPermissions())) + .notice(translation -> translation.warp().noPermission()) + .send(); + return; + } + this.warpTeleportService.teleport(player, warp); } + + private boolean hasPermission(Player player, Warp warp) { + List permissions = warp.getPermissions(); + if (permissions.isEmpty()) { + return true; + } + + return permissions + .stream() + .anyMatch(permission -> player.hasPermission(permission)); + } + } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfigRepresenter.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfigRepresenter.java deleted file mode 100644 index a2b2bebba..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfigRepresenter.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.eternalcode.core.feature.warp.repository; - -import com.eternalcode.commons.bukkit.position.Position; -import java.util.List; -import net.dzikoysk.cdn.entity.Contextual; - -@Contextual -class WarpConfigRepresenter { - public Position position; - public List permissions; - - WarpConfigRepresenter() { - } - - public WarpConfigRepresenter(Position position, List permissions) { - this.position = position; - this.permissions = permissions; - } -} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java index 366ebd8dd..2d0d609ca 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java @@ -1,10 +1,13 @@ package com.eternalcode.core.feature.warp.repository; +import com.eternalcode.commons.bukkit.position.Position; import com.eternalcode.core.configuration.ReloadableConfig; import com.eternalcode.core.injector.annotations.component.ConfigurationFile; import java.io.File; import java.util.HashMap; +import java.util.List; import java.util.Map; +import net.dzikoysk.cdn.entity.Contextual; import net.dzikoysk.cdn.entity.Description; import net.dzikoysk.cdn.entity.Exclude; import net.dzikoysk.cdn.source.Resource; @@ -17,10 +20,24 @@ class WarpDataConfig implements ReloadableConfig { public static final String WARP_DATA_FILE_PATH = "data" + File.separator + "warps.yml"; @Description({"# Warps data", "# These are warp locations, for your own safety, please don't touch it."}) - public Map warps = new HashMap<>(); + public Map warps = new HashMap<>(); @Override public Resource resource(File folder) { return Source.of(folder, WARP_DATA_FILE_PATH); } + + @Contextual + static class WarpConfigEntry { + public Position position; + public List permissions; + + WarpConfigEntry() { + } + + public WarpConfigEntry(Position position, List permissions) { + this.position = position; + this.permissions = permissions; + } + } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java index 8135f59e0..e71a95385 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java @@ -44,12 +44,12 @@ class WarpRepositoryImpl implements WarpRepository { @Override public CompletableFuture saveWarp(Warp warp) { - WarpConfigRepresenter warpConfigRepresenter = new WarpConfigRepresenter( + WarpDataConfig.WarpConfigEntry warpConfigEntry = new WarpDataConfig.WarpConfigEntry( PositionAdapter.convert(warp.getLocation()), warp.getPermissions() ); - return this.transactionalRun(warps -> warps.put(warp.getName(), warpConfigRepresenter)); + return this.transactionalRun(warps -> warps.put(warp.getName(), warpConfigEntry)); } @Override @@ -60,10 +60,10 @@ public CompletableFuture removeWarp(String warp) { @Override public CompletableFuture> getWarp(String name) { return transactionalSupply(warps -> Optional.ofNullable(this.warpDataConfig.warps.get(name)) - .map(warpConfigRepresenter -> new WarpImpl( + .map(warpConfigEntry -> new WarpImpl( name, - warpConfigRepresenter.position, - warpConfigRepresenter.permissions) + warpConfigEntry.position, + warpConfigEntry.permissions) )); } @@ -71,7 +71,7 @@ public CompletableFuture> getWarp(String name) { public CompletableFuture> getWarps() { return transactionalSupply(warps -> warps.entrySet().stream() .map(warpConfigEntry -> { - WarpConfigRepresenter warpContextual = warpConfigEntry.getValue(); + WarpDataConfig.WarpConfigEntry warpContextual = warpConfigEntry.getValue(); return new WarpImpl(warpConfigEntry.getKey(), warpContextual.position, warpContextual.permissions); }) .collect(Collectors.toList())); @@ -88,7 +88,7 @@ private void migrateWarps() { .stream() .collect(Collectors.toMap( entry -> entry.getKey(), - entry -> new WarpConfigRepresenter(entry.getValue(), new ArrayList<>())) + entry -> new WarpDataConfig.WarpConfigEntry(entry.getValue(), new ArrayList<>())) ) )); @@ -97,17 +97,17 @@ private void migrateWarps() { } } - private CompletableFuture transactionalRun(Consumer> editor) { + private CompletableFuture transactionalRun(Consumer> editor) { return transactionalSupply(warps -> { editor.accept(warps); return null; }); } - private CompletableFuture transactionalSupply(Function, T> editor) { + private CompletableFuture transactionalSupply(Function, T> editor) { return scheduler.completeAsync(() -> { synchronized (READ_WRITE_LOCK) { - Map warps = new HashMap<>(this.warpDataConfig.warps); + Map warps = new HashMap<>(this.warpDataConfig.warps); T result = editor.apply(warps); this.warpDataConfig.warps.putAll(warps); this.configurationManager.save(this.warpDataConfig); From c9d7dafe8bb8e7d6c9add3eff193692948472361 Mon Sep 17 00:00:00 2001 From: Rollczi Date: Sun, 12 Jan 2025 15:58:30 +0100 Subject: [PATCH 18/21] Fix gui permissions --- .../eternalcode/core/feature/warp/Warp.java | 12 +++++++++- .../core/feature/warp/WarpImpl.java | 5 ---- .../core/feature/warp/WarpInventory.java | 23 ++++++++++++------- .../feature/warp/command/WarpCommand.java | 16 +------------ 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java index 93227722c..0287b1645 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/Warp.java @@ -3,6 +3,7 @@ import org.bukkit.Location; import java.util.List; +import org.bukkit.permissions.Permissible; public interface Warp { @@ -12,6 +13,15 @@ public interface Warp { List getPermissions(); - boolean hasPermission(String permission); + default boolean hasPermissions(Permissible permissible) { + List permissions = this.getPermissions(); + if (permissions.isEmpty()) { + return true; + } + + return permissions + .stream() + .anyMatch(permission -> permissible.hasPermission(permission)); + } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java index bb35686d8..425692291 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpImpl.java @@ -35,9 +35,4 @@ public List getPermissions() { return Collections.unmodifiableList(this.permissions); } - @Override - public boolean hasPermission(String permission) { - return this.permissions.contains(permission); - } - } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java index 297718c1e..92a86423b 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java @@ -63,7 +63,12 @@ public class WarpInventory { this.config = config; } - private Gui createInventory(Language language) { + public void openInventory(Player player, Language language) { + this.createInventory(player, language) + .open(player); + } + + private Gui createInventory(Player player, Language language) { Translation translation = this.translationManager.getMessages(language); Translation.WarpSection.WarpInventorySection warpSection = translation.warp().warpInventory(); @@ -87,7 +92,7 @@ private Gui createInventory(Language language) { .disableAllInteractions() .create(); - this.createWarpItems(warpSection, gui); + this.createWarpItems(player, warpSection, gui); this.createBorder(warpSection, gui); this.createDecorations(warpSection, gui); @@ -146,7 +151,7 @@ private void createDecorations(WarpInventorySection warpSection, Gui gui) { } } - private void createWarpItems(WarpInventorySection warpSection, Gui gui) { + private void createWarpItems(Player player, WarpInventorySection warpSection, Gui gui) { warpSection.items().values().forEach(item -> { Optional warpOptional = this.warpManager.findWarp(item.warpName()); @@ -157,11 +162,17 @@ private void createWarpItems(WarpInventorySection warpSection, Gui gui) { Warp warp = warpOptional.get(); ConfigItem warpItem = item.warpItem(); + if (!warp.hasPermissions(player)) { + return; + } + BaseItemBuilder baseItemBuilder = this.createItem(warpItem); GuiItem guiItem = baseItemBuilder.asGuiItem(); guiItem.setAction(event -> { - Player player = (Player) event.getWhoClicked(); + if (!warp.hasPermissions(player)) { + return; + } player.closeInventory(); this.warpTeleportService.teleport(player, warp); @@ -193,10 +204,6 @@ private BaseItemBuilder createItem(ConfigItem item) { .glow(item.glow()); } - public void openInventory(Player player, Language language) { - this.createInventory(language).open(player); - } - public void addWarp(Warp warp) { if (!this.warpManager.isExist(warp.getName())) { return; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java index e0503e0ca..2b1e052d2 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java @@ -6,7 +6,6 @@ import com.eternalcode.core.feature.warp.WarpInventory; import com.eternalcode.core.feature.warp.WarpService; import com.eternalcode.core.feature.warp.WarpTeleportService; -import com.eternalcode.core.feature.warp.event.PreWarpTeleportEvent; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.notice.NoticeService; import com.eternalcode.core.user.User; @@ -16,8 +15,6 @@ import dev.rollczi.litecommands.annotations.execute.Execute; import dev.rollczi.litecommands.annotations.permission.Permission; import java.util.List; -import java.util.Optional; -import java.util.UUID; import org.bukkit.entity.Player; @RootCommand @@ -75,7 +72,7 @@ void warp(@Context Player player, @Context User user) { @Execute(name = "warp") @DescriptionDocs(description = "Teleport to warp, if player has permission eternalcore.warp.bypass teleport will be instant", arguments = "") void warp(@Context Player player, @Arg Warp warp) { - if (!this.hasPermission(player, warp)) { + if (!warp.hasPermissions(player)) { this.noticeService.create() .player(player.getUniqueId()) .placeholder("{WARP}", warp.getName()) @@ -88,15 +85,4 @@ void warp(@Context Player player, @Arg Warp warp) { this.warpTeleportService.teleport(player, warp); } - private boolean hasPermission(Player player, Warp warp) { - List permissions = warp.getPermissions(); - if (permissions.isEmpty()) { - return true; - } - - return permissions - .stream() - .anyMatch(permission -> player.hasPermission(permission)); - } - } From c6115be361c0e0bb99bd6607199fb2bc44d66f0c Mon Sep 17 00:00:00 2001 From: Rollczi Date: Sun, 12 Jan 2025 15:59:50 +0100 Subject: [PATCH 19/21] Fix cdn --- .../{WarpDataConfig.java => WarpConfig.java} | 4 ++-- .../warp/repository/WarpRepositoryImpl.java | 24 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) rename eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/{WarpDataConfig.java => WarpConfig.java} (94%) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java similarity index 94% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java index 2d0d609ca..182ffdf78 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpDataConfig.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java @@ -14,7 +14,7 @@ import net.dzikoysk.cdn.source.Source; @ConfigurationFile -class WarpDataConfig implements ReloadableConfig { +class WarpConfig implements ReloadableConfig { @Exclude public static final String WARP_DATA_FILE_PATH = "data" + File.separator + "warps.yml"; @@ -32,7 +32,7 @@ static class WarpConfigEntry { public Position position; public List permissions; - WarpConfigEntry() { + public WarpConfigEntry() { } public WarpConfigEntry(Position position, List permissions) { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java index e71a95385..d3f19b7a4 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java @@ -24,7 +24,7 @@ class WarpRepositoryImpl implements WarpRepository { private static final Object READ_WRITE_LOCK = new Object(); private final LocationsConfiguration locationsConfiguration; - private final WarpDataConfig warpDataConfig; + private final WarpConfig warpConfig; private final ConfigurationManager configurationManager; private final Scheduler scheduler; @@ -32,11 +32,11 @@ class WarpRepositoryImpl implements WarpRepository { WarpRepositoryImpl( ConfigurationManager configurationManager, LocationsConfiguration locationsConfiguration, - WarpDataConfig warpDataConfig, Scheduler scheduler + WarpConfig warpConfig, Scheduler scheduler ) { this.locationsConfiguration = locationsConfiguration; this.configurationManager = configurationManager; - this.warpDataConfig = warpDataConfig; + this.warpConfig = warpConfig; this.scheduler = scheduler; this.migrateWarps(); @@ -44,7 +44,7 @@ class WarpRepositoryImpl implements WarpRepository { @Override public CompletableFuture saveWarp(Warp warp) { - WarpDataConfig.WarpConfigEntry warpConfigEntry = new WarpDataConfig.WarpConfigEntry( + WarpConfig.WarpConfigEntry warpConfigEntry = new WarpConfig.WarpConfigEntry( PositionAdapter.convert(warp.getLocation()), warp.getPermissions() ); @@ -59,7 +59,7 @@ public CompletableFuture removeWarp(String warp) { @Override public CompletableFuture> getWarp(String name) { - return transactionalSupply(warps -> Optional.ofNullable(this.warpDataConfig.warps.get(name)) + return transactionalSupply(warps -> Optional.ofNullable(this.warpConfig.warps.get(name)) .map(warpConfigEntry -> new WarpImpl( name, warpConfigEntry.position, @@ -71,7 +71,7 @@ public CompletableFuture> getWarp(String name) { public CompletableFuture> getWarps() { return transactionalSupply(warps -> warps.entrySet().stream() .map(warpConfigEntry -> { - WarpDataConfig.WarpConfigEntry warpContextual = warpConfigEntry.getValue(); + WarpConfig.WarpConfigEntry warpContextual = warpConfigEntry.getValue(); return new WarpImpl(warpConfigEntry.getKey(), warpContextual.position, warpContextual.permissions); }) .collect(Collectors.toList())); @@ -88,7 +88,7 @@ private void migrateWarps() { .stream() .collect(Collectors.toMap( entry -> entry.getKey(), - entry -> new WarpDataConfig.WarpConfigEntry(entry.getValue(), new ArrayList<>())) + entry -> new WarpConfig.WarpConfigEntry(entry.getValue(), new ArrayList<>())) ) )); @@ -97,20 +97,20 @@ private void migrateWarps() { } } - private CompletableFuture transactionalRun(Consumer> editor) { + private CompletableFuture transactionalRun(Consumer> editor) { return transactionalSupply(warps -> { editor.accept(warps); return null; }); } - private CompletableFuture transactionalSupply(Function, T> editor) { + private CompletableFuture transactionalSupply(Function, T> editor) { return scheduler.completeAsync(() -> { synchronized (READ_WRITE_LOCK) { - Map warps = new HashMap<>(this.warpDataConfig.warps); + Map warps = new HashMap<>(this.warpConfig.warps); T result = editor.apply(warps); - this.warpDataConfig.warps.putAll(warps); - this.configurationManager.save(this.warpDataConfig); + this.warpConfig.warps.putAll(warps); + this.configurationManager.save(this.warpConfig); return result; } }); From cec9d900b84085d27f797a8205644ca82c657c45 Mon Sep 17 00:00:00 2001 From: Rollczi Date: Sun, 12 Jan 2025 16:29:51 +0100 Subject: [PATCH 20/21] Fix cdn --- .../eternalcode/core/feature/warp/repository/WarpConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java index 182ffdf78..9a3d4528b 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java @@ -28,7 +28,7 @@ public Resource resource(File folder) { } @Contextual - static class WarpConfigEntry { + public static class WarpConfigEntry { public Position position; public List permissions; From 72feb45bb60c2f8d2b2e26b44610cf20ba320f8f Mon Sep 17 00:00:00 2001 From: Martin Sulikowski Date: Sun, 12 Jan 2025 16:46:25 +0100 Subject: [PATCH 21/21] Fix cdn. --- .../core/feature/warp/repository/WarpConfig.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java index 9a3d4528b..c6bf4a26c 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java @@ -14,17 +14,14 @@ import net.dzikoysk.cdn.source.Source; @ConfigurationFile -class WarpConfig implements ReloadableConfig { - - @Exclude - public static final String WARP_DATA_FILE_PATH = "data" + File.separator + "warps.yml"; +public class WarpConfig implements ReloadableConfig { @Description({"# Warps data", "# These are warp locations, for your own safety, please don't touch it."}) public Map warps = new HashMap<>(); @Override public Resource resource(File folder) { - return Source.of(folder, WARP_DATA_FILE_PATH); + return Source.of(folder, "data" + File.separator + "warps.yml"); } @Contextual