From 94080e41dd173eaba1dd22bf2b59e5ce195798dc Mon Sep 17 00:00:00 2001 From: Zerthick Date: Sat, 9 Jul 2016 14:25:08 -0400 Subject: [PATCH] Update to Sponge API 5.0.0-SNAPSHOT --- build.gradle | 12 ++++++------ .../protectionperms/ProtectionPermsMain.java | 5 ++++- .../PrimaryBlockListener.java | 19 +++++++++++++++++-- .../SecondaryBlockListener.java | 19 +++++++++++++++++-- .../PrimaryEntityListener.java | 19 +++++++++++++++++-- .../SecondaryEntityListener.java | 19 +++++++++++++++++-- .../item/useItemStackEvent/StartListener.java | 2 +- 7 files changed, 79 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index d19eec2..7600acf 100644 --- a/build.gradle +++ b/build.gradle @@ -17,12 +17,12 @@ * along with ProtectionPerms. If not, see . */ -group 'zerthick.github.io' -version '0.2.0' - -apply plugin: 'java' +plugins { + id 'org.spongepowered.plugin' version '0.6' + id 'java' +} -sourceCompatibility = 1.8 +group 'io.github.zerthick' repositories { mavenCentral() @@ -33,5 +33,5 @@ repositories { } dependencies { - compile 'org.spongepowered:spongeapi:4.1.0-SNAPSHOT' + compile 'org.spongepowered:spongeapi:5.0.0-SNAPSHOT' } diff --git a/src/main/java/io/github/zerthick/protectionperms/ProtectionPermsMain.java b/src/main/java/io/github/zerthick/protectionperms/ProtectionPermsMain.java index 1688bc3..61cdb3b 100644 --- a/src/main/java/io/github/zerthick/protectionperms/ProtectionPermsMain.java +++ b/src/main/java/io/github/zerthick/protectionperms/ProtectionPermsMain.java @@ -28,7 +28,10 @@ import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; -@Plugin(id = "ProtectionPerms", name = "ProtectionPerms", version = "0.2.0") +@Plugin(id = "protectionperms", + name = "ProtectionPerms", + version = "0.3.0", + description = "A simple player protection and control plugin.") public class ProtectionPermsMain { @Inject diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java index 5eb6899..bfc5005 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java @@ -19,6 +19,7 @@ package io.github.zerthick.protectionperms.events.listeners.item.interactBlockEvent; +import org.spongepowered.api.data.type.HandTypes; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.block.InteractBlockEvent; @@ -33,8 +34,22 @@ public class PrimaryBlockListener { @Listener - public void onInteractBlockPrimary(InteractBlockEvent.Primary event, @First Player player) { - Optional itemStackOptional = player.getItemInHand(); + public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary.MainHand event, @First Player player) { + Optional itemStackOptional = player.getItemInHand(HandTypes.MAIN_HAND); + if(itemStackOptional.isPresent()) { + String blockName = event.getTargetBlock().getState().getType().getName(); + String itemName = itemStackOptional.get().getItem().getName(); + if (!player.hasPermission("protectionPerms.item.use." + itemName + ".on." + blockName + ".primary")) { + event.setCancelled(true); + player.sendMessage(ChatTypes.ACTION_BAR, + Text.of(TextColors.RED, "You don't have permission to primary use " + itemName + " on " + blockName + '!')); + } + } + } + + @Listener + public void onInteractBlockPrimaryOff(InteractBlockEvent.Primary.OffHand event, @First Player player) { + Optional itemStackOptional = player.getItemInHand(HandTypes.OFF_HAND); if(itemStackOptional.isPresent()) { String blockName = event.getTargetBlock().getState().getType().getName(); String itemName = itemStackOptional.get().getItem().getName(); diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java index 415c515..d1329fb 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java @@ -19,6 +19,7 @@ package io.github.zerthick.protectionperms.events.listeners.item.interactBlockEvent; +import org.spongepowered.api.data.type.HandTypes; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.block.InteractBlockEvent; @@ -33,8 +34,22 @@ public class SecondaryBlockListener { @Listener - public void onInteractBlockSecondary(InteractBlockEvent.Secondary event, @First Player player) { - Optional itemStackOptional = player.getItemInHand(); + public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary.MainHand event, @First Player player) { + Optional itemStackOptional = player.getItemInHand(HandTypes.MAIN_HAND); + if(itemStackOptional.isPresent()) { + String blockName = event.getTargetBlock().getState().getType().getName(); + String itemName = itemStackOptional.get().getItem().getName(); + if (!player.hasPermission("protectionPerms.item.use." + itemName + ".on." + blockName + ".secondary")) { + event.setCancelled(true); + player.sendMessage(ChatTypes.ACTION_BAR, + Text.of(TextColors.RED, "You don't have permission to secondary use " + itemName + " on " + blockName + '!')); + } + } + } + + @Listener + public void onInteractBlockSecondaryOff(InteractBlockEvent.Secondary.OffHand event, @First Player player) { + Optional itemStackOptional = player.getItemInHand(HandTypes.OFF_HAND); if(itemStackOptional.isPresent()) { String blockName = event.getTargetBlock().getState().getType().getName(); String itemName = itemStackOptional.get().getItem().getName(); diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/PrimaryEntityListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/PrimaryEntityListener.java index 6cf56b3..b34342f 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/PrimaryEntityListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/PrimaryEntityListener.java @@ -19,6 +19,7 @@ package io.github.zerthick.protectionperms.events.listeners.item.interactEntityEvent; +import org.spongepowered.api.data.type.HandTypes; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.entity.InteractEntityEvent; @@ -33,8 +34,22 @@ public class PrimaryEntityListener { @Listener - public void onInteractEntityPrimary(InteractEntityEvent.Primary event, @First Player player) { - Optional itemStackOptional = player.getItemInHand(); + public void onInteractEntityPrimaryMain(InteractEntityEvent.Primary.MainHand event, @First Player player) { + Optional itemStackOptional = player.getItemInHand(HandTypes.MAIN_HAND); + if(itemStackOptional.isPresent()) { + String entityName = event.getTargetEntity().getType().getName(); + String itemName = itemStackOptional.get().getItem().getName(); + if (!player.hasPermission("protectionPerms.item.use." + itemName + ".on." + entityName + ".primary")) { + event.setCancelled(true); + player.sendMessage(ChatTypes.ACTION_BAR, + Text.of(TextColors.RED, "You don't have permission to primary use " + itemName + " on " + entityName + '!')); + } + } + } + + @Listener + public void onInteractEntityPrimaryOff(InteractEntityEvent.Primary.OffHand event, @First Player player) { + Optional itemStackOptional = player.getItemInHand(HandTypes.OFF_HAND); if(itemStackOptional.isPresent()) { String entityName = event.getTargetEntity().getType().getName(); String itemName = itemStackOptional.get().getItem().getName(); diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/SecondaryEntityListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/SecondaryEntityListener.java index ab9b170..c5a6aa5 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/SecondaryEntityListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/SecondaryEntityListener.java @@ -19,6 +19,7 @@ package io.github.zerthick.protectionperms.events.listeners.item.interactEntityEvent; +import org.spongepowered.api.data.type.HandTypes; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.entity.InteractEntityEvent; @@ -33,8 +34,22 @@ public class SecondaryEntityListener { @Listener - public void onInteractEntitySecondary(InteractEntityEvent.Secondary event, @First Player player) { - Optional itemStackOptional = player.getItemInHand(); + public void onInteractEntitySecondaryMain(InteractEntityEvent.Secondary.MainHand event, @First Player player) { + Optional itemStackOptional = player.getItemInHand(HandTypes.MAIN_HAND); + if(itemStackOptional.isPresent()) { + String entityName = event.getTargetEntity().getType().getName(); + String itemName = itemStackOptional.get().getItem().getName(); + if (!player.hasPermission("protectionPerms.item.use." + itemName + ".on." + entityName + ".primary")) { + event.setCancelled(true); + player.sendMessage(ChatTypes.ACTION_BAR, + Text.of(TextColors.RED, "You don't have permission to secondary use " + itemName + " on " + entityName + '!')); + } + } + } + + @Listener + public void onInteractEntitySecondaryOff(InteractEntityEvent.Secondary.OffHand event, @First Player player) { + Optional itemStackOptional = player.getItemInHand(HandTypes.OFF_HAND); if(itemStackOptional.isPresent()) { String entityName = event.getTargetEntity().getType().getName(); String itemName = itemStackOptional.get().getItem().getName(); diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/useItemStackEvent/StartListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/useItemStackEvent/StartListener.java index 357a1dc..79fd2ef 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/useItemStackEvent/StartListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/useItemStackEvent/StartListener.java @@ -30,7 +30,7 @@ public class StartListener { @Listener public void onItemUse(UseItemStackEvent.Start event, @First Player player) { - String itemName = event.getItemStackInUse().getOriginal().getType().getName(); + String itemName = event.getItemStackInUse().getType().getName(); if (!player.hasPermission("protectionPerms.item.use." + itemName)) { event.setCancelled(true); player.sendMessage(Text.of(TextColors.RED, "You don't have permission to use " + itemName + '!'));