PvP Permissions

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

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

    Snowybearr

    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

    Beno65Dev

    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

    Snowybearr

    Beno65Dev
    Not sure I follow you?

    AndrewAnderVille
    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:
    Code:java
    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

    Snowybearr

    AndrewAnderVille
    How does this look:
    Code:java
    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();
    6.  
    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. }
    15.  
    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

    Snowybearr

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

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

    Snowybearr

    AndrewAnderVille
    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:

    Code:java
    1. package main.unity.pvp;
    2.  
    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;
    9.  
    10. public class Main extends JavaPlugin {
    11.  
    12. public static Main plugin;
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14.  
    15. @Override
    16. public void onEnable(){
    17. PluginDescriptionFile pdfFile = this.getDescription();
    18. this.logger.info(pdfFile.getName() + " Has Been Enabled." + pdfFile.getVersion());
    19. }
    20.  
    21. public void onDisable(){
    22. PluginDescriptionFile pdfFile = this.getDescription();
    23. this.logger.info(pdfFile.getName() + " Has Been Disabled.");
    24. }
    25.  
    26.  
    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();
    32.  
    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. }
    41.  
    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. }
    53.  


    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

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


    and the other one
     
  11. Offline

    Snowybearr

    AndrewAnderVille
    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