-
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.
Refactor drop listener to utilize entity filtering, add non-functiona…
…l forge and brew listeners, enable smelting listener, update to API 6.0.
- Loading branch information
Showing
7 changed files
with
127 additions
and
21 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
42 changes: 42 additions & 0 deletions
42
src/main/java/io/github/zerthick/protectionperms/events/listeners/item/BrewItemListener.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,42 @@ | ||
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.Getter; | ||
import org.spongepowered.api.event.filter.cause.Root; | ||
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; | ||
import org.spongepowered.api.item.inventory.Inventory; | ||
import org.spongepowered.api.item.inventory.InventoryArchetypes; | ||
import org.spongepowered.api.item.inventory.slot.FuelSlot; | ||
import org.spongepowered.api.item.inventory.slot.InputSlot; | ||
import org.spongepowered.api.text.Text; | ||
import org.spongepowered.api.text.chat.ChatTypes; | ||
import org.spongepowered.api.text.format.TextColors; | ||
|
||
public class BrewItemListener { | ||
|
||
@Listener | ||
public void onItemSmelt(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) { | ||
|
||
if (inventory.getArchetype() == InventoryArchetypes.BREWING_STAND) { | ||
|
||
Inventory brewingInputs = inventory.query(InputSlot.class); | ||
|
||
brewingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> { | ||
String itemId = itemStack.getItem().getType().getId(); | ||
|
||
if (slot instanceof FuelSlot) { | ||
if (!player.hasPermission("protectionperms.item.fuel." + itemId)) { | ||
event.setCancelled(true); | ||
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemId + " as fuel!")); | ||
} | ||
} else { | ||
if (!player.hasPermission("protectionperms.item.brew." + itemId)) { | ||
event.setCancelled(true); | ||
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to brew " + itemId + '!')); | ||
} | ||
} | ||
})); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDeathListener.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,28 @@ | ||
package io.github.zerthick.protectionperms.events.listeners.item; | ||
|
||
import org.spongepowered.api.entity.EntityTypes; | ||
import org.spongepowered.api.entity.Item; | ||
import org.spongepowered.api.entity.living.player.Player; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.cause.entity.spawn.EntitySpawnCause; | ||
import org.spongepowered.api.event.filter.cause.Root; | ||
import org.spongepowered.api.event.item.inventory.DropItemEvent; | ||
|
||
public class DropItemDeathListener { | ||
|
||
@Listener | ||
public void onItemDropDeath(DropItemEvent.Destruct event, @Root EntitySpawnCause spawnCause) { | ||
|
||
if (spawnCause.getEntity() instanceof Player) { | ||
Player player = (Player) spawnCause.getEntity(); | ||
event.filterEntities(entity -> { | ||
if (entity.getType().equals(EntityTypes.ITEM)) { | ||
Item item = (Item) entity; | ||
String itemId = item.getItemType().getId(); | ||
return player.hasPermission("protectionperms.item.drop." + itemId + ".death"); | ||
} | ||
return true; | ||
}); | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...main/java/io/github/zerthick/protectionperms/events/listeners/item/ForgeItemListener.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,34 @@ | ||
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.Getter; | ||
import org.spongepowered.api.event.filter.cause.Root; | ||
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; | ||
import org.spongepowered.api.item.inventory.Inventory; | ||
import org.spongepowered.api.item.inventory.InventoryArchetypes; | ||
import org.spongepowered.api.item.inventory.slot.InputSlot; | ||
import org.spongepowered.api.text.Text; | ||
import org.spongepowered.api.text.chat.ChatTypes; | ||
import org.spongepowered.api.text.format.TextColors; | ||
|
||
public class ForgeItemListener { | ||
|
||
@Listener | ||
public void onItemForge(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) { | ||
|
||
if (inventory.getArchetype() == InventoryArchetypes.ANVIL) { | ||
|
||
Inventory forgingInputs = inventory.query(InputSlot.class); | ||
|
||
forgingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> { | ||
String itemId = itemStack.getItem().getType().getId(); | ||
if (!player.hasPermission("protectionperms.item.forge." + itemId)) { | ||
event.setCancelled(true); | ||
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to forge " + itemId + '!')); | ||
} | ||
})); | ||
} | ||
} | ||
|
||
} |
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