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..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 @@ -2,10 +2,26 @@ import org.bukkit.Location; +import java.util.List; +import org.bukkit.permissions.Permissible; + public interface Warp { Location getLocation(); String getName(); + List getPermissions(); + + 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-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..62aedd920 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,6 +4,7 @@ import java.util.Collection; import java.util.Optional; +import org.jetbrains.annotations.ApiStatus.Experimental; public interface WarpService { @@ -11,11 +12,15 @@ public interface WarpService { void removeWarp(String warp); - boolean warpExists(String name); + @Experimental + Warp addPermissions(String warp, String... permissions); - Optional findWarp(String name); + @Experimental + Warp removePermissions(String warp, String... permissions); + + boolean isExist(String name); - Collection getNamesOfWarps(); + Optional findWarp(String name); - boolean hasWarps(); + Collection getWarps(); } 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/configuration/implementation/LocationsConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java index 2f4801004..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 @@ -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; @@ -21,7 +21,8 @@ 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<>(); @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 cce6e1b29..2123c0ef6 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 @@ -5,15 +5,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.jail.JailSettings; import com.eternalcode.core.feature.helpop.HelpOpSettings; +import com.eternalcode.core.feature.jail.JailSettings; import com.eternalcode.core.feature.randomteleport.RandomTeleportSettingsImpl; import com.eternalcode.core.feature.spawn.SpawnSettings; import com.eternalcode.core.injector.annotations.Bean; import com.eternalcode.core.injector.annotations.component.ConfigurationFile; import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings; -import java.util.LinkedHashMap; -import java.util.Set; import net.dzikoysk.cdn.entity.Contextual; import net.dzikoysk.cdn.entity.Description; import net.dzikoysk.cdn.entity.Exclude; @@ -24,7 +22,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 { @@ -352,7 +352,6 @@ public static class Warp { @Description("# Texture of the item (only for PLAYER_HEAD material)") public String itemTexture = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk4ODVlODIzZmYxNTkyNjdjYmU4MDkwOTNlMzNhNDc2ZTI3NDliNjU5OGNhNGEyYTgxZWU2OTczODAzZmI2NiJ9fX0="; - } @Description({ " ", "# Butcher" }) 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 fccf84828..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpConfigRepository.java +++ /dev/null @@ -1,61 +0,0 @@ -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.injector.annotations.Inject; -import com.eternalcode.core.injector.annotations.component.Service; -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; -import panda.std.Option; - -@Service -class WarpConfigRepository implements WarpRepository { - - private final LocationsConfiguration locationsConfiguration; - private final ConfigurationManager configurationManager; - - @Inject - WarpConfigRepository(ConfigurationManager configurationManager, LocationsConfiguration locationsConfiguration) { - this.locationsConfiguration = locationsConfiguration; - this.configurationManager = configurationManager; - } - - @Override - public void addWarp(Warp warp) { - this.edit(warps -> warps.put(warp.getName(), PositionAdapter.convert(warp.getLocation()))); - } - - @Override - public void removeWarp(String warp) { - this.edit(warps -> warps.remove(warp)); - } - - private void edit(Consumer> editor) { - HashMap warps = new HashMap<>(this.locationsConfiguration.warps); - - editor.accept(warps); - - this.locationsConfiguration.warps = warps; - this.configurationManager.save(this.locationsConfiguration); - } - - @Override - public CompletableFuture> getWarp(String name) { - return CompletableFuture.completedFuture(Optional.of(this.locationsConfiguration.warps.get(name)) - .map(location -> new WarpImpl(name, location))); - } - - @Override - public CompletableFuture> getWarps() { - return CompletableFuture.completedFuture(this.locationsConfiguration.warps.entrySet().stream() - .map(entry -> new WarpImpl(entry.getKey(), entry.getValue())) - .collect(Collectors.toList())); - } -} 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..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 @@ -2,16 +2,22 @@ import com.eternalcode.commons.bukkit.position.Position; import com.eternalcode.commons.bukkit.position.PositionAdapter; +import java.util.ArrayList; import org.bukkit.Location; -class WarpImpl implements Warp { +import java.util.Collections; +import java.util.List; + +public class WarpImpl implements Warp { private final String name; private final Position position; + private final List permissions; - WarpImpl(String name, Position position) { + public WarpImpl(String name, Position position, List permissions) { this.name = name; this.position = position; + this.permissions = new ArrayList<>(permissions); } @Override @@ -23,4 +29,10 @@ public String getName() { public Location getLocation() { return PositionAdapter.convert(this.position); } + + @Override + public List getPermissions() { + return Collections.unmodifiableList(this.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 03f1b97eb..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 @@ -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 { @@ -62,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(); @@ -80,14 +86,13 @@ private Gui createInventory(Language language) { } } - Gui gui = Gui.gui() .title(this.miniMessage.deserialize(warpSection.title())) .rows(rowsCount) .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,18 +204,12 @@ 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.warpExists(warp.getName())) { + if (!this.warpManager.isExist(warp.getName())) { return; } for (Language language : this.translationManager.getAvailableLanguages()) { - AbstractTranslation translation = (AbstractTranslation) this.translationManager.getMessages(language); Translation.WarpSection.WarpInventorySection warpSection = translation.warp().warpInventory(); @@ -245,7 +250,7 @@ public void addWarp(Warp warp) { public boolean removeWarp(String warpName) { - if (!this.warpManager.warpExists(warpName)) { + if (!this.warpManager.isExist(warpName)) { return false; } 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 f07b081d6..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpRepository.java +++ /dev/null @@ -1,16 +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); - - 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..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 @@ -2,13 +2,17 @@ import com.eternalcode.annotations.scan.feature.FeatureDocs; import com.eternalcode.commons.bukkit.position.PositionAdapter; +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; 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( @@ -18,7 +22,7 @@ @Service class WarpServiceImpl implements WarpService { - private final Map warpMap = new HashMap<>(); + private final Map warps = new ConcurrentHashMap<>(); private final WarpRepository warpRepository; @Inject @@ -27,26 +31,24 @@ private WarpServiceImpl(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) { - 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); + this.warps.put(name, warp); + this.warpRepository.saveWarp(warp); return warp; } @Override public void removeWarp(String warp) { - Warp remove = this.warpMap.remove(warp); - + Warp remove = this.warps.remove(warp); if (remove == null) { return; } @@ -55,22 +57,50 @@ public void removeWarp(String warp) { } @Override - public boolean warpExists(String name) { - return this.warpMap.containsKey(name); + 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 Optional findWarp(String name) { - return Optional.ofNullable(this.warpMap.get(name)); + public Warp removePermissions(String warpName, String... permissions) { + Warp warp = this.modifyPermissions(warpName, perms -> perms.removeAll(List.of(permissions))); + this.warpRepository.saveWarp(warp); + return warp; + } + + private Warp modifyPermissions(String warpName, Consumer> modifier) { + Warp warp = this.warps.get(warpName); + if (warp == null) { + throw new IllegalArgumentException("Warp " + warpName + " does not exist"); + } + + List updatedPermissions = new ArrayList<>(warp.getPermissions()); + modifier.accept(updatedPermissions); + + Warp updatedWarp = new WarpImpl( + warp.getName(), + PositionAdapter.convert(warp.getLocation()), + updatedPermissions + ); + + this.warps.put(warpName, updatedWarp); + return updatedWarp; } @Override - public Collection getNamesOfWarps() { - return Collections.unmodifiableCollection(this.warpMap.keySet()); + public boolean isExist(String name) { + return this.warps.containsKey(name); + } + + @Override + public Optional findWarp(String name) { + return Optional.ofNullable(this.warps.get(name)); } @Override - public boolean hasWarps() { - return !this.warpMap.isEmpty(); + public Collection getWarps() { + return Collections.unmodifiableCollection(this.warps.values()); } } 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/DelWarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java index c76774b25..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.warpExists(name)) { + if (!this.warpService.isExist(name)) { this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().notExist()) 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 a0f29e53b..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 @@ -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 { @@ -43,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.isExist(warp)) { this.noticeService.create() .player(uniqueId) .notice(translation -> translation.warp().warpAlreadyExists()) @@ -62,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.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 5b5b6946b..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.getNamesOfWarps().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 ec5f12370..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 @@ -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.getNamesOfWarps())) + .placeholder("{WARPS}", String.join(this.config.format.separator, list)) .send(); return; } - if (!this.warpService.hasWarps()) { + if (this.warpService.getWarps().isEmpty()) { this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().noWarps()) @@ -69,6 +72,17 @@ 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 (!warp.hasPermissions(player)) { + 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); } + } 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 new file mode 100644 index 000000000..86ff4159c --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpAddPermissionCommand.java @@ -0,0 +1,69 @@ +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; +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 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(PluginConfiguration config, WarpService warpService, NoticeService noticeService) { + this.config = config; + 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; + } + + 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) + .placeholder("{WARP}", warp.getName()) + .notice(translation -> translation.warp().addPermissions()) + .send(); + } +} 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 new file mode 100644 index 000000000..3cddadb02 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/WarpRemovePermissionCommand.java @@ -0,0 +1,55 @@ +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.WarpPermissionEntry; +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; + +@Command(name = "warp-permission remove") +@Permission("eternalcore.warp.changepermissions") +public class WarpRemovePermissionCommand { + + private final WarpService warpService; + private final NoticeService noticeService; + + @Inject + public WarpRemovePermissionCommand(WarpService warpService, NoticeService noticeService) { + this.warpService = warpService; + this.noticeService = noticeService; + } + + @Execute + void removePermission( + @Context Player player, + @Arg WarpPermissionEntry entry + ) { + Warp warp = entry.warp(); + String permission = entry.permission(); + + if (!warp.getPermissions().contains(permission)) { + this.noticeService.create() + .placeholder("{WARP}", warp.getName()) + .placeholder("{PERMISSION}", permission) + .player(player.getUniqueId()) + .notice(translation -> translation.warp().permissionDoesNotExist()) + .send(); + return; + } + + this.warpService.removePermissions(warp.getName(), permission); + + this.noticeService.create() + .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/WarpPermissionEntry.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionEntry.java new file mode 100644 index 000000000..46e26fef8 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionEntry.java @@ -0,0 +1,6 @@ +package com.eternalcode.core.feature.warp.command.permission.argument; + +import com.eternalcode.core.feature.warp.Warp; + +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 new file mode 100644 index 000000000..5d66b658f --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/permission/argument/WarpPermissionMultiArgumentResolver.java @@ -0,0 +1,123 @@ +package com.eternalcode.core.feature.warp.command.permission.argument; + +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 = WarpPermissionEntry.class) +public class WarpPermissionMultiArgumentResolver + implements MultipleArgumentResolver { + + private static final String WARP_PLACEHOLDER_PREFIX = "{WARP}"; + private final WarpService warpService; + private final NoticeService noticeService; + private final ViewerService viewerService; + + @Inject + public WarpPermissionMultiArgumentResolver( + WarpService warpService, + NoticeService noticeService, + ViewerService viewerService + ) { + 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().missingWarpArgument()) + .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()) { + return ParseResult.failure(this.noticeService.create() + .notice(translation -> translation.warp().missingPermissionArgument()) + .viewer(viewer) + ); + } + + String permission = rawInput.next(); + return ParseResult.success(new WarpPermissionEntry(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.getWarps().stream() + .map(Warp::getName) + .toList() + ); + } + + if (index == 2) { + String warpName = current.multilevelList().getFirst(); + 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/repository/WarpConfig.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java new file mode 100644 index 000000000..c6bf4a26c --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpConfig.java @@ -0,0 +1,40 @@ +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; +import net.dzikoysk.cdn.source.Source; + +@ConfigurationFile +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, "data" + File.separator + "warps.yml"); + } + + @Contextual + public static 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/repository/WarpRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepository.java new file mode 100644 index 000000000..367136cc7 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepository.java @@ -0,0 +1,17 @@ +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 WarpRepository { + + CompletableFuture saveWarp(Warp warp); + + CompletableFuture removeWarp(String warp); + + CompletableFuture> getWarp(String name); + + CompletableFuture> getWarps(); +} 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 new file mode 100644 index 000000000..d3f19b7a4 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java @@ -0,0 +1,119 @@ +package com.eternalcode.core.feature.warp.repository; + +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; +import com.eternalcode.core.feature.warp.WarpImpl; +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.injector.annotations.component.Repository; +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.function.Function; +import java.util.stream.Collectors; + +@Repository +class WarpRepositoryImpl implements WarpRepository { + + private static final Object READ_WRITE_LOCK = new Object(); + + private final LocationsConfiguration locationsConfiguration; + private final WarpConfig warpConfig; + private final ConfigurationManager configurationManager; + private final Scheduler scheduler; + + @Inject + WarpRepositoryImpl( + ConfigurationManager configurationManager, + LocationsConfiguration locationsConfiguration, + WarpConfig warpConfig, Scheduler scheduler + ) { + this.locationsConfiguration = locationsConfiguration; + this.configurationManager = configurationManager; + this.warpConfig = warpConfig; + this.scheduler = scheduler; + + this.migrateWarps(); + } + + @Override + public CompletableFuture saveWarp(Warp warp) { + WarpConfig.WarpConfigEntry warpConfigEntry = new WarpConfig.WarpConfigEntry( + PositionAdapter.convert(warp.getLocation()), + warp.getPermissions() + ); + + return this.transactionalRun(warps -> warps.put(warp.getName(), warpConfigEntry)); + } + + @Override + public CompletableFuture removeWarp(String warp) { + return this.transactionalRun(warps -> warps.remove(warp)); + } + + @Override + public CompletableFuture> getWarp(String name) { + return transactionalSupply(warps -> Optional.ofNullable(this.warpConfig.warps.get(name)) + .map(warpConfigEntry -> new WarpImpl( + name, + warpConfigEntry.position, + warpConfigEntry.permissions) + )); + } + + @Override + public CompletableFuture> getWarps() { + return transactionalSupply(warps -> warps.entrySet().stream() + .map(warpConfigEntry -> { + WarpConfig.WarpConfigEntry warpContextual = warpConfigEntry.getValue(); + return new WarpImpl(warpConfigEntry.getKey(), warpContextual.position, warpContextual.permissions); + }) + .collect(Collectors.toList())); + } + + private void migrateWarps() { + 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 WarpConfig.WarpConfigEntry(entry.getValue(), new ArrayList<>())) + ) + )); + + this.locationsConfiguration.warps.clear(); + this.configurationManager.save(this.locationsConfiguration); + } + } + + 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.warpConfig.warps); + T result = editor.apply(warps); + this.warpConfig.warps.putAll(warps); + this.configurationManager.save(this.warpConfig); + return result; + } + }); + } + +} 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 8b1ed970b..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 @@ -1,8 +1,8 @@ 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; @@ -152,6 +152,14 @@ interface WarpSection { Notice itemAdded(); Notice noWarps(); Notice itemLimit(); + Notice noPermission(); + Notice addPermissions(); + Notice removePermission(); + Notice permissionDoesNotExist(); + Notice permissionAlreadyExist(); + Notice noPermissionsProvided(); + 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 0abcc395c..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 @@ -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; @@ -381,6 +382,15 @@ 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})!"); + 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!"); + public Notice permissionAlreadyExist = Notice.chat("Permission {PERMISSION} already exists!"); + public Notice noPermissionAssigned = Notice.chat("There are no permissions assigned to this warp!"); + 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}"); @@ -393,7 +403,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 d8fa66581..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 @@ -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; @@ -105,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!"); @@ -307,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!"); } @@ -383,10 +384,21 @@ public static class PLWarpSection implements WarpSection { public Notice notExist = Notice.chat("Nie odnaleziono takiego warpu!"); 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 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 addPermissions = Notice.chat("Dodano uprawnienia do warpa {WARP}!"); + 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 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}!"); + @Description({" ", "# Ustawienia gui listy dostępnych warpów"}) public PLWarpInventory warpInventory = new PLWarpInventory(); @@ -406,7 +418,6 @@ public void setItems(Map items) { this.items = items; } - public PLBorderSection border = new PLBorderSection(); public PLDecorationItemsSection decorationItems = new PLDecorationItemsSection(); @@ -463,7 +474,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}!"); @@ -628,6 +639,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();