Skip to content

Commit

Permalink
Merge pull request #8 from Zerthick/API-7
Browse files Browse the repository at this point in the history
Api 7
  • Loading branch information
Zerthick authored Jan 2, 2018
2 parents 80dda89 + 5ae344f commit f8cecf1
Show file tree
Hide file tree
Showing 26 changed files with 199 additions and 99 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ plugins {
}

group 'io.github.zerthick'
version '1.1.0'

repositories {
mavenCentral()
Expand All @@ -33,13 +34,13 @@ repositories {
}
}

spongestart {
spongestart{
eula true

minecraft '1.11.2'
minecraft '1.12.2'
type 'stable'
}

dependencies {
compile 'org.spongepowered:spongeapi:6.0.0'
compile 'org.spongepowered:spongeapi:7.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public PluginContainer getInstance() {
@Listener
public void onServerInit(GameInitializationEvent event) {

DebugLogger.getInstance().setLogger(logger);

//Register Event Listeners
ListenerRegister.registerListeners(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.github.zerthick.protectionperms.events.listeners.block.changeBlockEvent;

import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
Expand All @@ -37,14 +38,16 @@ public class BreakListener {
public void onBlockBreak(ChangeBlockEvent.Break event, @Root Player player) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> transaction : transactions) {

BlockSnapshot snapshot = transaction.getOriginal();
String blockTypeId = snapshot.getState().getType().getId();
String blockStateId = snapshot.getState().getId();
BlockState blockState = snapshot.getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
if (!player.hasPermission("protectionperms.block.break." + blockTypeId) &&
!player.hasPermission("protectionperms.block.break." + blockStateId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to break " + blockStateId + '!'));
Text.of(TextColors.RED, "You don't have permission to break " + blockState.getName() + '!'));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.github.zerthick.protectionperms.events.listeners.block.changeBlockEvent;

import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
Expand All @@ -37,14 +38,16 @@ public class PlaceListener {
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> transaction : transactions) {

BlockSnapshot snapshot = transaction.getFinal();
String blockTypeId = snapshot.getState().getType().getId();
String blockStateId = snapshot.getState().getId();
BlockState blockState = snapshot.getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
if (!player.hasPermission("protectionperms.block.place." + blockTypeId) &&
!player.hasPermission("protectionperms.block.place." + blockStateId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to place " + blockStateId + '!'));
Text.of(TextColors.RED, "You don't have permission to place " + blockState.getName() + '!'));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package io.github.zerthick.protectionperms.events.listeners.block.interactBlockEvent;

import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.InteractBlockEvent;
Expand All @@ -31,13 +32,15 @@ public class PrimaryListener {

@Listener
public void onInteractBlockPrimary(InteractBlockEvent.Primary event, @Root Player player) {
String blockTypeId = event.getTargetBlock().getState().getType().getId();
String blockStateId = event.getTargetBlock().getState().getId();

BlockState blockState = event.getTargetBlock().getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
if (!player.hasPermission("protectionperms.block.interact." + blockTypeId + ".primary") &&
!player.hasPermission("protectionperms.block.interact." + blockStateId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to primary interact with " + blockStateId + '!'));
Text.of(TextColors.RED, "You don't have permission to primary interact with " + blockState.getName() + '!'));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package io.github.zerthick.protectionperms.events.listeners.block.interactBlockEvent;

import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.InteractBlockEvent;
Expand All @@ -31,13 +32,15 @@ public class SecondaryListener {

@Listener
public void onInteractBlockSecondary(InteractBlockEvent.Secondary event, @Root Player player) {
String blockTypeId = event.getTargetBlock().getState().getType().getId();
String blockStateId = event.getTargetBlock().getState().getId();

BlockState blockState = event.getTargetBlock().getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
if (!player.hasPermission("protectionperms.block.interact." + blockTypeId + ".secondary") &&
!player.hasPermission("protectionperms.block.interact." + blockStateId + ".secondary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to secondary interact with " + blockStateId + '!'));
Text.of(TextColors.RED, "You don't have permission to secondary interact with " + blockState.getName() + '!'));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package io.github.zerthick.protectionperms.events.listeners.entity;

import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource;
Expand All @@ -34,11 +35,12 @@ public class DamageEntityListener {
public void onEntityDamage(DamageEntityEvent event, @Root EntityDamageSource dmgSource) {
if(dmgSource.getSource() instanceof Player) {
Player player = (Player)dmgSource.getSource();
String entityId = event.getTargetEntity().getType().getId();
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
if (!player.hasPermission("protectionperms.entity.damage." + entityId + ".deal")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to damage " + entityId + "s!"));
Text.of(TextColors.RED, "You don't have permission to damage " + entityType.getName() + "s!"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public EntityListenerManager() {
listeners.add(new DamageEntityListener());
listeners.add(new RideEntityMountListener());
listeners.add(new TameEntityListener());
//listeners.add(new HookEntityListener());
listeners.add(new HookEntityListener());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package io.github.zerthick.protectionperms.events.listeners.entity;

import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.action.FishingEvent;
import org.spongepowered.api.event.filter.cause.First;
import org.spongepowered.api.event.cause.EventContextKeys;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.format.TextColors;

public class HookEntityListener {

@Listener
public void onEntityHook(FishingEvent.HookEntity event, @First Player player) {
public void onEntityHook(FishingEvent.HookEntity event) {

player.sendMessage(Text.of("Test"));
event.getContext().get(EventContextKeys.OWNER).ifPresent(user ->

user.getPlayer().ifPresent(player -> {

EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
if (!player.hasPermission("protectionperms.entity.hook." + entityId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to hook " + entityType.getName() + "s!"));
}

})

);

String entityId = event.getTargetEntity().getType().getId();
if (!player.hasPermission("protectionperms.entity.hook." + entityId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to hook " + entityId + "s!"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package io.github.zerthick.protectionperms.events.listeners.entity;

import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.RideEntityEvent;
Expand All @@ -31,11 +32,13 @@ public class RideEntityMountListener {

@Listener
public void onEntityMount(RideEntityEvent.Mount event, @Root Player player) {
String entityId = event.getTargetEntity().getType().getId();

EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
if (!player.hasPermission("protectionperms.entity.mount." + entityId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to mount " + entityId + "s!"));
Text.of(TextColors.RED, "You don't have permission to mount " + entityType.getName() + "s!"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package io.github.zerthick.protectionperms.events.listeners.entity;

import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.TameEntityEvent;
Expand All @@ -31,11 +32,13 @@ public class TameEntityListener {

@Listener
public void onEntityTame(TameEntityEvent event, @Root Player player) {
String entityId = event.getTargetEntity().getType().getId();

EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
if (!player.hasPermission("protectionperms.entity.tame." + entityId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to tame " + entityId + "s!"));
Text.of(TextColors.RED, "You don't have permission to tame " + entityType.getName() + "s!"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package io.github.zerthick.protectionperms.events.listeners.entity.interactEntityEvent;

import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.InteractEntityEvent;
Expand All @@ -31,11 +32,13 @@ public class PrimaryListener {

@Listener
public void onInteractEntityPrimary(InteractEntityEvent.Primary event, @Root Player player) {
String entityId = event.getTargetEntity().getType().getId();

EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
if (!player.hasPermission("protectionperms.entity.interact." + entityId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to primary interact with " + entityId + "s!"));
Text.of(TextColors.RED, "You don't have permission to primary interact with " + entityType.getName() + "s!"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package io.github.zerthick.protectionperms.events.listeners.entity.interactEntityEvent;

import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.InteractEntityEvent;
Expand All @@ -31,11 +32,13 @@ public class SecondaryListener {

@Listener
public void onInteractEntitySecondary(InteractEntityEvent.Secondary event, @Root Player player) {
String entityId = event.getTargetEntity().getType().getId();

EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
if (!player.hasPermission("protectionperms.entity.interact." + entityId + ".secondary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to secondary interact with " + entityId + "s!"));
Text.of(TextColors.RED, "You don't have permission to secondary interact with " + entityType.getName() + "s!"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
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.filter.cause.First;
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.InventoryArchetypes;
import org.spongepowered.api.item.inventory.crafting.CraftingOutput;
import org.spongepowered.api.item.inventory.query.QueryOperationTypes;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.format.TextColors;
Expand All @@ -16,17 +18,19 @@
public class CraftItemListener {

@Listener
public void onItemCraft(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
public void onItemCraft(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {

if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {

Inventory craftingOutputs = inventory.query(CraftingOutput.class);
Inventory craftingOutputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingOutput.class));

craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
String itemId = itemStack.getItem().getType().getId();

ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
if (!player.hasPermission("protectionperms.item.craft." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemId + '!'));
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemType.getName() + '!'));
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
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) {
public void onItemDropDeath(DropItemEvent.Destruct event, @Root Player player) {

if (spawnCause.getEntity() instanceof Player) {
Player player = (Player) spawnCause.getEntity();
event.filterEntities(entity -> {
if (entity.getType().equals(EntityTypes.ITEM)) {
Item item = (Item) entity;
Expand All @@ -23,6 +20,5 @@ public void onItemDropDeath(DropItemEvent.Destruct event, @Root EntitySpawnCause
}
return true;
});
}
}
}
Loading

0 comments on commit f8cecf1

Please sign in to comment.