mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
Allow spectators to edit inventories
Requires permission OpenInv.spectate Closes #155
This commit is contained in:
parent
1a6d513603
commit
da55790fd2
4 changed files with 29 additions and 7 deletions
|
@ -136,6 +136,10 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
|
||||||
<td>OpenInv.silent.default</td>
|
<td>OpenInv.silent.default</td>
|
||||||
<td>Cause SilentContainer to be enabled by default.</td>
|
<td>Cause SilentContainer to be enabled by default.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.spectate</td>
|
||||||
|
<td>Allows users in spectate gamemode to edit inventories.</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
## For Developers
|
## For Developers
|
||||||
|
|
|
@ -19,6 +19,7 @@ package com.lishid.openinv.listeners;
|
||||||
import com.lishid.openinv.IOpenInv;
|
import com.lishid.openinv.IOpenInv;
|
||||||
import com.lishid.openinv.util.InventoryAccess;
|
import com.lishid.openinv.util.InventoryAccess;
|
||||||
import com.lishid.openinv.util.Permissions;
|
import com.lishid.openinv.util.Permissions;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -56,23 +57,38 @@ public class InventoryListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
onInventoryInteract(event);
|
onInventoryInteract(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onInventoryDrag(InventoryDragEvent event) {
|
public void onInventoryDrag(InventoryDragEvent event) {
|
||||||
onInventoryInteract(event);
|
onInventoryInteract(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onInventoryInteract(InventoryInteractEvent event) {
|
private void onInventoryInteract(InventoryInteractEvent event) {
|
||||||
HumanEntity entity = event.getWhoClicked();
|
HumanEntity entity = event.getWhoClicked();
|
||||||
|
|
||||||
|
if (Permissions.SPECTATE.hasPermission(entity) && entity.getGameMode() == GameMode.SPECTATOR) {
|
||||||
|
event.setCancelled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Inventory inventory = event.getInventory();
|
Inventory inventory = event.getInventory();
|
||||||
if (InventoryAccess.isPlayerInventory(inventory) && !Permissions.EDITINV.hasPermission(entity)
|
|
||||||
|| InventoryAccess.isEnderChest(inventory) && !Permissions.EDITENDER.hasPermission(entity)) {
|
if (InventoryAccess.isPlayerInventory(inventory)) {
|
||||||
|
if (!Permissions.EDITINV.hasPermission(entity)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
} else if (InventoryAccess.isEnderChest(inventory)) {
|
||||||
|
if (!Permissions.EDITENDER.hasPermission(entity)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ public enum Permissions {
|
||||||
EDITENDER("editender"),
|
EDITENDER("editender"),
|
||||||
OPENSELF("openself"),
|
OPENSELF("openself"),
|
||||||
OPENONLINE("openonline"),
|
OPENONLINE("openonline"),
|
||||||
OPENOFFLINE("openoffline");
|
OPENOFFLINE("openoffline"),
|
||||||
|
SPECTATE("spectate");
|
||||||
|
|
||||||
private final String permission;
|
private final String permission;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ author: lishid
|
||||||
authors: [Jikoo, ShadowRanger]
|
authors: [Jikoo, ShadowRanger]
|
||||||
description: >
|
description: >
|
||||||
This plugin allows you to open a player's inventory as a chest and interact with it in real time.
|
This plugin allows you to open a player's inventory as a chest and interact with it in real time.
|
||||||
api-version: "1.14"
|
api-version: "1.15"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
OpenInv.any.default:
|
OpenInv.any.default:
|
||||||
|
@ -27,6 +27,7 @@ permissions:
|
||||||
OpenInv.searchcontainer: true
|
OpenInv.searchcontainer: true
|
||||||
OpenInv.openonline: true
|
OpenInv.openonline: true
|
||||||
OpenInv.openoffline: true
|
OpenInv.openoffline: true
|
||||||
|
OpenInv.spectate: true
|
||||||
OpenInv.openinv:
|
OpenInv.openinv:
|
||||||
default: op
|
default: op
|
||||||
children:
|
children:
|
||||||
|
|
Loading…
Reference in a new issue