-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump to version 1.1.0, add unfinished PickupItem Listener
- Loading branch information
Showing
4 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ain/java/io/github/zerthick/protectionperms/events/listeners/item/PickupItemListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.zerthick.protectionperms.events.listeners.item; | ||
|
||
import org.spongepowered.api.entity.living.player.Player; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.filter.cause.Root; | ||
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; | ||
import org.spongepowered.api.item.ItemType; | ||
import org.spongepowered.api.item.inventory.ItemStackSnapshot; | ||
import org.spongepowered.api.text.Text; | ||
import org.spongepowered.api.text.chat.ChatTypes; | ||
import org.spongepowered.api.text.format.TextColors; | ||
|
||
public class PickupItemListener { | ||
|
||
@Listener | ||
public void onItemDrop(ChangeInventoryEvent.Pickup event, @Root Player player) { | ||
|
||
event.getTransactions().forEach(slotTransaction -> { | ||
ItemStackSnapshot stackSnapshot = slotTransaction.getFinal(); | ||
|
||
ItemType itemType = stackSnapshot.getType(); | ||
String itemId = itemType.getId(); | ||
|
||
if (!player.hasPermission("protectionperms.item.pickup." + itemId)) { | ||
event.setCancelled(true); | ||
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to pick up " + itemType.getName() + '!')); | ||
} | ||
}); | ||
} | ||
} |