Skip to content

Commit

Permalink
新增盔甲架、展示框权限控制(归属到普通容器)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Mar 14, 2024
1 parent be3fd70 commit da8aa00
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@

## 指令

### 玩家指令

以下指令尖括号`<>`表示必填参数,方括号`[]`表示可选参数。

### 玩家指令

| 指令名 | 指令 |
|------------|-------------------------------------------------------------|
| 打开交互菜单 | `/dominion menu` |
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.11.9-beta</version>
<version>1.11.10-beta</version>
<packaging>jar</packaging>

<name>Dominion</name>
Expand Down
74 changes: 61 additions & 13 deletions src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cn.lunadeer.dominion.utils.Notification;
import io.papermc.paper.event.entity.EntityDyeEvent;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
Expand All @@ -22,6 +23,7 @@
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.*;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.persistence.PersistentDataType;
import org.spigotmc.event.entity.EntityMountEvent;

public class PlayerEvents implements Listener {
Expand Down Expand Up @@ -314,6 +316,29 @@ public void eatCake(PlayerInteractEvent event) {
event.setCancelled(true);
}

// 检查是否有容器权限
private static boolean hasContainerPermission(Player player) {
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player);
if (dom == null) {
return true;
}
if (Apis.hasPermission(player, dom)) {
return true;
}
PlayerPrivilegeDTO privilege = Cache.instance.getPlayerPrivilege(player, dom);
if (privilege != null) {
if (privilege.getContainer()) {
return true;
}
} else {
if (dom.getContainer()) {
return true;
}
}
Notification.error(player, "你没有使用容器/盔甲架/展示框的权限");
return false;
}

@EventHandler(priority = EventPriority.HIGHEST) // container
public void openContainer(InventoryOpenEvent event) {
if (event.getInventory().getType() != InventoryType.CHEST &&
Expand All @@ -325,24 +350,47 @@ public void openContainer(InventoryOpenEvent event) {
return;
}
Player bukkitPlayer = (Player) event.getPlayer();
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer);
if (dom == null) {
if (hasContainerPermission(bukkitPlayer)) {
return;
}
if (Apis.hasPermission(bukkitPlayer, dom)) {
event.setCancelled(true);
}

@EventHandler(priority = EventPriority.HIGHEST) // container (armor stand)
public void manipulateArmorStand(PlayerArmorStandManipulateEvent event) {
Player bukkitPlayer = event.getPlayer();
if (hasContainerPermission(bukkitPlayer)) {
return;
}
PlayerPrivilegeDTO privilege = Cache.instance.getPlayerPrivilege(bukkitPlayer, dom);
if (privilege != null) {
if (privilege.getContainer()) {
return;
}
} else {
if (dom.getContainer()) {
return;
}
event.setCancelled(true);
}

@EventHandler(priority = EventPriority.HIGHEST) // container (item frame)
public void putSomeOnItemFrame(PlayerInteractEntityEvent event) {
Entity entity = event.getRightClicked();
if (!(entity instanceof ItemFrame)) {
return;
}
Player bukkitPlayer = event.getPlayer();
if (hasContainerPermission(bukkitPlayer)) {
return;
}
event.setCancelled(true);
}

@EventHandler(priority = EventPriority.HIGHEST) // container (item frame)
public void removeSomeOnItemFrame(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof ItemFrame)) {
return;
}
if (!(event.getDamager() instanceof Player)) {
return;
}
Player bukkitPlayer = (Player) event.getDamager();
if (hasContainerPermission(bukkitPlayer)) {
return;
}
Notification.error(bukkitPlayer, "你没有使用容器的权限");
event.setCancelled(true);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/lunadeer/dominion/tuis/DominionFlagInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public static void show(CommandSender sender, String[] args) {
if (dominion.getContainer()) {
view.add(Line.create()
.append(Button.createGreen("☑", "/dominion set container false " + dominion.getName() + " " + page))
.append("箱子/木桶/潜影盒"));
.append("箱子/木桶/潜影盒/盔甲架/展示框"));
} else {
view.add(Line.create()
.append(Button.createRed("☐", "/dominion set container true " + dominion.getName() + " " + page))
.append("箱子/木桶/潜影盒"));
.append("箱子/木桶/潜影盒/盔甲架/展示框"));
}
if (dominion.getCraft()) {
view.add(Line.create()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/lunadeer/dominion/tuis/PrivilegeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ public static void show(CommandSender sender, String[] args) {
if (privilege.getContainer()) {
view.add(Line.create()
.append(Button.createGreen("☑", "/dominion set_privilege " + playerName + " container false " + dominion.getName() + " " + page))
.append("箱子/木桶/潜影盒"));
.append("箱子/木桶/潜影盒/盔甲架/展示框"));
} else {
view.add(Line.create()
.append(Button.createRed("☐", "/dominion set_privilege " + playerName + " container true " + dominion.getName() + " " + page))
.append("箱子/木桶/潜影盒"));
.append("箱子/木桶/潜影盒/盔甲架/展示框"));
}
if (privilege.getCraft()) {
view.add(Line.create()
Expand Down

0 comments on commit da8aa00

Please sign in to comment.