PvP Permissions

Discussion in 'Plugin Development' started by Snowybearr, Jun 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    Hey all. I am working on a team based PvP plugin that has 2 teams which each have their own permission group using GroupManager.

    What I am trying to figure out is how I can make it so one team can kill the other team but not members of the same team. Think of it as Red vs Blue for simplicity, red can kill blue and blue can kill red, but red can't kill red and blue can't kill blue.

    I'd like to make it simple and just be able to put like pvp.red and pvp.blue for each group. Those would be permissions that make a team part of an actual side/team.

    Any help would be greatly appreciated, thanks.
  2. Offline


    the problem that teammates can hit each other to create a scoreboard, I do not know exactly how to do it but there are plenty of tutorials how to do it
  3. Listen for when players attack each other. Then, when the event is called, cancel if the attacker and the damaged player have the same permission (pvp.red or pvp.blue)
  4. Offline


    Not sure I follow you?

    Yeah the part that confuses me really is how do I 'compare' the permissions? And if they happen to be part of the same team how do you block that damage from happening? Just return false?

    Here is what I have:
    1. public void onEntityDamage(EntityDamageEvent e) {
    2. if (e.getEntity() instanceof Player && e instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent)e).getDamager() instanceof Player) {
    3. // Permission check here
    4. }
    5. }
  5. First get both entities as players. Then check if player one has "pvp.red". If player one does, check if player two does too. Do the same for both permissions. If both have the same permission, cancel the event which will stop the damage.

    EDIT: Also, instead of using an EntityDamageEvent, I would use an EntityDamageByEntityEvent.
  6. Offline


    How does this look:
    1. @EventHandler
    2. public void onEntityDamage(EntityDamageByEntityEvent e) {
    3. if (e.getEntity() instanceof Player && e instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent)e).getDamager() instanceof Player) {
    4. Player p = (Player) e.getEntity();
    5. Player hitter = (Player) e.getDamager();
    7. //Permission Check Red
    8. if(hitter.hasPermission("pvp.red")){
    9. if(p.hasPermission("pvp.red")){
    10. e.setCancelled(true);
    11. }else{
    12. return;
    13. }
    14. }
    16. //Permission Check Blue
    17. if(hitter.hasPermission("pvp.blue")){
    18. if(p.hasPermission("pvp.blue")){
    19. e.setCancelled(true);
    20. }else{
    21. return;
    22. }
    23. }
    24. }
    25. }
    26. }
  7. Offline


  8. Not sure if this is the issue but try changing this
    1. if (e.getEntity() instanceof Player && e instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent)e).getDamager() instanceof Player) {

    to this
    1. if (e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
  9. Offline


    Same issue. To double check I removed the plugin and used the same 2 accounts in the same spot and they were able to damage each other. So it for sure has something to do with this. It looks right to me, not sure what the issue is.

    Anything else you can think of?

    I got it sort of working, but the first 2 hits against a player does nothing, then starts working.

    Does anyone know how to fix this issue? Here is the full source to take a look at it all:

    1. package main.unity.pvp;
    3. import java.util.logging.Logger;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    7. import org.bukkit.plugin.PluginDescriptionFile;
    8. import org.bukkit.plugin.java.JavaPlugin;
    10. public class Main extends JavaPlugin {
    12. public static Main plugin;
    13. public final Logger logger = Logger.getLogger("Minecraft");
    15. @Override
    16. public void onEnable(){
    17. PluginDescriptionFile pdfFile = this.getDescription();
    18. this.logger.info(pdfFile.getName() + " Has Been Enabled." + pdfFile.getVersion());
    19. }
    21. public void onDisable(){
    22. PluginDescriptionFile pdfFile = this.getDescription();
    23. this.logger.info(pdfFile.getName() + " Has Been Disabled.");
    24. }
    27. @EventHandler
    28. public void onEntityDamage(EntityDamageByEntityEvent e) {
    29. if (e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
    30. Player p = (Player) e.getEntity();
    31. Player hitter = (Player) e.getDamager();
    33. //Permission Check Red
    34. if(hitter.hasPermission("pvp.red")){
    35. if(p.hasPermission("pvp.red")){
    36. e.setCancelled(true);
    37. }else{
    38. return;
    39. }
    40. }
    42. //Permission Check Blue
    43. if(hitter.hasPermission("pvp.blue")){
    44. if(p.hasPermission("pvp.blue")){
    45. e.setCancelled(true);
    46. }else{
    47. return;
    48. }
    49. }
    50. }
    51. }
    52. }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 8, 2016
  10. Remove the else statements in

    1. if(p.hasPermission("pvp.red")){
    2. e.setCancelled(true);
    3. }else{
    4. return;

    and the other one
  11. Offline


    Yeah I was wondering if those were actually needed or not. So I have found the issues though. For some reason when you first join a server you have some sort of immunity or something? But that is why nothing was happening when I tested PvP.

    As for the plugin itself, everything was correct I just was a derp and forgot to implement listener lol.

    Thanks for all your help AndrewAnderVille! :)
Thread Status:
Not open for further replies.

Share This Page