Skip to content

Commit

Permalink
Add fishing start listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthick committed Jan 9, 2018
1 parent e19772e commit 110eccc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.zerthick.protectionperms.events.listeners.item;

import io.github.zerthick.protectionperms.PermHandler;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.action.FishingEvent;
import org.spongepowered.api.event.cause.EventContext;
import org.spongepowered.api.event.cause.EventContextKeys;
import org.spongepowered.api.event.filter.Getter;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.format.TextColors;

public class FishingStartListener {

@Listener
public void onItemUse(FishingEvent.Start event, @Root Player player, @Getter("getContext") EventContext context) {

context.get(EventContextKeys.USED_ITEM).ifPresent(itemStackSnapshot -> {
ItemType itemType = itemStackSnapshot.getType();
String itemId = itemType.getId();

PermHandler ph = PermHandler.getInstance();

if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on.self")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemType.getName() + '!'));
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public ItemListenerManager() {
//*listeners.add(new BrewItemListener());
listeners.add(new EquipItemListener());
listeners.add(new PickupItemListener());
listeners.add(new FishingStartListener());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onItemUse(UseItemStackEvent.Start event, @Root Player player) {

PermHandler ph = PermHandler.getInstance();

if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on.self")) {
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemType.getName() + '!'));
}
Expand Down

0 comments on commit 110eccc

Please sign in to comment.