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..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 @@ -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 doesWarpPermissionExist(String warp, String permission); + Optional findWarp(String name); Collection getNamesOfWarps(); 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 11cf299f2..0ab8e854c 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,14 +6,12 @@ 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.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; @@ -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 { @@ -346,7 +346,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/configuration/implementation/WarpsConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java new file mode 100644 index 000000000..d9fca3da7 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/WarpsConfiguration.java @@ -0,0 +1,25 @@ +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/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 03f1b97eb..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 @@ -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 { @@ -80,7 +81,6 @@ private Gui createInventory(Language language) { } } - Gui gui = Gui.gui() .title(this.miniMessage.deserialize(warpSection.title())) .rows(rowsCount) @@ -198,13 +198,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..b01da97dd --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpPermissionController.java @@ -0,0 +1,62 @@ +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 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) { + 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()) + .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 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 8b1ed970b..8f0762b14 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,11 @@ interface WarpSection { Notice itemAdded(); 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 0abcc395c..cc93e15e2 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,7 +382,11 @@ 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!"); @Description({" ", "# {WARPS} - List of warps (separated by commas)"}) public Notice available = Notice.chat("Available warps: {WARPS}"); @@ -393,7 +398,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..2a2a224d1 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; @@ -383,7 +384,12 @@ 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} 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}!"); @@ -406,7 +412,6 @@ public void setItems(Map items) { this.items = items; } - public PLBorderSection border = new PLBorderSection(); public PLDecorationItemsSection decorationItems = new PLDecorationItemsSection(); @@ -628,6 +633,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();