Skip to content

Commit

Permalink
Refactor and enhance warp permission handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy committed Jan 12, 2025
1 parent 1dbc78f commit 2e80db7
Show file tree
Hide file tree
Showing 24 changed files with 433 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ public interface Warp {

List<String> getPermissions();

void setPermissions(List<String> permissions);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Warp> findWarp(String name);

Collection<String> getNamesOfWarps();
Collection<String> getAllNames();

boolean hasWarps();
boolean isEmpty();
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<String> permissions;

WarpImpl(String name, Position position, List<String> permissions) {
public WarpImpl(String name, Position position, List<String> permissions) {
this.name = name;
this.position = position;
this.permissions = permissions;
this.permissions = new ArrayList<>(permissions);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down

This file was deleted.

Loading

0 comments on commit 2e80db7

Please sign in to comment.