-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-835 Add permission-based access to warps #856
base: master
Are you sure you want to change the base?
Changes from 1 commit
fca57f8
65e7564
374fc89
f1a6ada
7eb3bfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Simplify method parameters by removing redundant The Apply this diff to simplify the method: -private void checkWarpPermission(PreWarpTeleportEvent event, Warp warp, Player player, UUID uniqueId) {
+private void checkWarpPermission(PreWarpTeleportEvent event, Warp warp, Player player) { Update the usage of - .player(uniqueId)
+ .player(player.getUniqueId()) And adjust the method call in -this.checkWarpPermission(event, warp, player, uniqueId);
+this.checkWarpPermission(event, warp, player);
|
||
Map<String, Set<String>> warpPermissions = this.pluginConfiguration.warp.warpPermissions; | ||
|
||
if (!warpPermissions.containsKey(warp.getName())) { | ||
return; | ||
} | ||
|
||
Set<String> permissions = warpPermissions.get(warp.getName()); | ||
Optional<String> isPlayerAllowedToUseWarp = permissions | ||
.stream() | ||
.filter(player::hasPermission) | ||
.findAny(); | ||
|
||
if (isPlayerAllowedToUseWarp.isPresent()) { | ||
return; | ||
} | ||
|
||
event.setCancelled(true); | ||
|
||
this.noticeService.create() | ||
.player(uniqueId) | ||
.placeholder("{WARP}", warp.getName()) | ||
eripe14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.notice(translation -> translation.warp().noPermission()) | ||
.send(); | ||
Comment on lines
+55
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance player feedback by including required permissions Currently, the player is notified that they lack permission to use the warp but does not know which permission is needed. Providing the specific permissions required can help players understand what is needed to access the warp. Consider modifying the notice to include the missing permissions: this.noticeService.create()
.player(uniqueId)
.placeholder("{WARP}", warp.getName())
+ .placeholder("{PERMISSIONS}", String.join(", ", permissions))
.notice(translation -> translation.warp().noPermission())
.send(); Ensure that the
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Missing Method Implementations in Translation Implementations The following methods declared in the
Please implement these methods to ensure full compliance with the 🔗 Analysis chainReactivated import statement The import statement for To ensure this import is necessary, let's verify its usage: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check if WarpInventoryItem is used in the file
grep -n "WarpInventoryItem" eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java
Length of output: 2781 |
||
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(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused
PluginConfiguration
dependencyThe
pluginConfiguration
field and its corresponding constructor parameter are declared but not used within the class. Removing unused fields helps keep the codebase clean and maintainable.Apply this diff to remove the unused field and constructor parameter:
📝 Committable suggestion