Remove shortcut item in worlds where the player doesn't have the permission to use it (#184)

This commit is contained in:
GeorgH93 2021-10-24 11:28:22 +02:00
parent 272d674007
commit ce1a5fca45
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
2 changed files with 22 additions and 3 deletions

View File

@ -123,6 +123,18 @@ else if(isItemShortcut(itemStack))
} }
} }
private void removeItem(Player player)
{
for(ItemStack itemStack : player.getInventory())
{
if(isItemShortcut(itemStack))
{
itemStack.setAmount(0);
return;
}
}
}
//region Add backpack item //region Add backpack item
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onJoin(PlayerJoinEvent event) public void onJoin(PlayerJoinEvent event)
@ -139,10 +151,17 @@ public void onSpawn(PlayerRespawnEvent event)
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onWorldChange(PlayerChangedWorldEvent event) public void onWorldChange(final PlayerChangedWorldEvent event)
{ {
if(plugin.isDisabled(event.getPlayer()) != WorldBlacklistMode.None) return; if(plugin.isDisabled(event.getPlayer()) != WorldBlacklistMode.None) return;
Bukkit.getScheduler().runTaskLater(plugin, () -> addItem(event.getPlayer()), 2L); Bukkit.getScheduler().runTaskLater(plugin, () -> {
Player player = event.getPlayer();
if(!player.isOnline()) return;
if(player.hasPermission(Permissions.USE))
addItem(player);
else
removeItem(player);
}, 2L);
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)

View File

@ -7,7 +7,7 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>
<revision>2.4.2</revision> <revision>2.4.3-RC1</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> </properties>