vanish on damage not working

Discussion in 'Plugin Development' started by AgentJayCraft, Aug 14, 2013.

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

    AgentJayCraft

    I want to make players vanish when Another player clicks them. And they are not seen only by the person who clicked them. Here is my Listener main and plugin.yml there are no errors but it doesnt work.
    Code:java
    1. package me.ggames62.PoP;
    2.  
    3. import org.bukkit.command.Command;
    4.  
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.plugin.PluginManager;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class PoP extends JavaPlugin{
    10. public static PoP plugin;
    11.  
    12. public void onEnable() {
    13. PluginManager pm = this.getServer().getPluginManager();
    14. pm.registerEvents(new PoPListener(this), this);
    15. }
    16.  
    17. public void onDisable() {
    18. }
    19.  
    20. public boolean onCommand(CommandSender sender, Command cmd,
    21. String commandLabel, String[] args) {
    22. return false;
    23. }
    24. }

    Code:java
    1. package me.ggames62.PoP;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Entity;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    9.  
    10. public class PoPListener implements Listener{
    11.  
    12. public static PoP plugin;
    13.  
    14. public PoPListener(PoP instance) {
    15. plugin = instance;
    16. }
    17.  
    18. @EventHandler
    19. public void onEntityByDamagerEntity(EntityDamageByEntityEvent event){
    20. Entity e = event.getDamager();
    21.  
    22. if(e instanceof Player) {
    23. Player player = (Player) e;
    24.  
    25. for(Player online : Bukkit.getOnlinePlayers()) {
    26. if(online.getName() != player.getName()) {
    27. online.hidePlayer(player);
    28. }
    29. }
    30.  
    31. }
    32. }
    33. }

    Code:java
    1. name: pop
    2. main: me.ggames62.PoP.PoP.PoPListener
    3. version: 1.0
    4.  


    Can someone please help me ive been trying to fix this for days

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    flaaghara

    main: me.ggames62.PoP.PoP

    You had the listener as your main class, but it isn't the one that extends JavaPlugin. Try that instead.
     
  3. Offline

    AgentJayCraft

  4. Offline

    Ghilliedrone

    Try this:
    Code:java
    1. public class PoP extends JavaPlugin implements Listener

    put the code from the listener class in this class
    also change the yml main to me.ggames62.PoP.PoP.PoP
     
  5. Offline

    AgentJayCraft

    Like this? and I still got errors

    package me.ggames62.PoP;

    import org.bukkit.Bukkit;

    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    publicclassPoPextends JavaPlugin implementsListener

    publicstatic PoP plugin;

    public PoPListener(PoP instance) {
    plugin = instance;
    }

    @EventHandler
    public void onEntityByDamagerEntity(EntityDamageByEntityEvent event){
    Entity e = event.getDamager();

    if(e instanceof Player) {
    Player player = (Player) e;

    for(Player online : Bukkit.getOnlinePlayers()) {
    if(online.getName() != player.getName()) {
    online.hidePlayer(player);
    }
    }

    }
    }
    }
     
  6. Offline

    Ghilliedrone

    AgentJayCraft
    Please use the code tags when outputting code
    Can you also post the error? It would speed things up
     
  7. Offline

    AgentJayCraft

    Code:java
    1. package me.ggames62.PoP;
    2.  
    3. import org.bukkit.Bukkit;
    4.  
    5. import org.bukkit.entity.Entity;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class PoP extends JavaPlugin implements Listener{
    13.  
    14. public static PoP plugin;
    15.  
    16. public PoPListener(PoP instance) {
    17. plugin = instance;
    18. }
    19.  
    20. @EventHandler
    21. public void onEntityByDamagerEntity(EntityDamageByEntityEvent event){
    22. Entity e = event.getDamager();
    23.  
    24. if(e instanceof Player) {
    25. Player player = (Player) e;
    26.  
    27. for(Player online : Bukkit.getOnlinePlayers()) {
    28. if(online.getName() != player.getName()) {
    29. online.hidePlayer(player);
    30. }
    31. }
    32.  
    33. }
    34. }
    35. }



    Pop: the public type pop must be defined in its own file
    PoPListener(PoP instance):return type for the method is missing
     
  8. Offline

    Ghilliedrone

    AgentJayCraft
    Get rid of the PoPListener class since all your code is in the main class
     
    AgentJayCraft likes this.
  9. Offline

    AgentJayCraft

    then where do I put the codes for the vanish? on the main class?
     
  10. Offline

    Ghilliedrone

    AgentJayCraft
    Yes. Also, make sure that PoP is the name of the java file
     
    AgentJayCraft likes this.
  11. Offline

    AgentJayCraft

    so like this?
    Code:java
    1. package me.ggames62.PoP;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Entity;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    10. import org.bukkit.plugin.PluginManager;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class PoP extends JavaPlugin{
    14. public static PoP plugin;
    15.  
    16. public void onEnable() {
    17. PluginManager pm = this.getServer().getPluginManager();
    18. pm.registerEvents(new PoPListener(this), this);
    19. }
    20.  
    21. public void onDisable() {
    22. }
    23.  
    24. @EventHandler
    25. public void onEntityByDamagerEntity(EntityDamageByEntityEvent event){
    26. Entity e = event.getDamager();
    27.  
    28. if(e instanceof Player) {
    29. Player player = (Player) e;
    30.  
    31. for(Player online : Bukkit.getOnlinePlayers()) {
    32. if(online.getName() != player.getName()) {
    33. online.hidePlayer(player);
    34. }
    35. }
    36.  
    37. }
    38. }
    39.  
    40.  
    41. public boolean onCommand(CommandSender sender, Command cmd,
    42. String commandLabel, String[] args) {
    43. return false;
    44. }
    45. }
     
  12. Offline

    Ghilliedrone

    AgentJayCraft
    Thats good. the public void onDisable is unnecessary since nothings in it
     
    AgentJayCraft likes this.
  13. Offline

    AgentJayCraft

    do I still have to register the Listener?
     
  14. Offline

    Ghilliedrone

    Yes, make sure
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    is in the onEnable
     
    AgentJayCraft likes this.
  15. Offline

    AgentJayCraft

    okay so I got a few more errors.
    implements:interface type expected after this token
    Listener: cannot instantiate type listener
    registerEvents:in the type PluginManager is not applicable for arguments pop pop

    Code:java
    1. package me.ggames62.PoP;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Entity;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    11. import org.bukkit.plugin.PluginManager;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class PoP extends JavaPlugin implements{
    15. public static PoP plugin;
    16.  
    17. public void onEnable() {
    18. PluginManager pm = this.getServer().getPluginManager();
    19. pm.registerEvents(new Listener(this), this);
    20. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    21. }
    22.  
    23. @EventHandler
    24. public void onEntityByDamagerEntity(EntityDamageByEntityEvent event){
    25. Entity e = event.getDamager();
    26.  
    27. if(e instanceof Player) {
    28. Player player = (Player) e;
    29.  
    30. for(Player online : Bukkit.getOnlinePlayers()) {
    31. if(online.getName() != player.getName()) {
    32. online.hidePlayer(player);
    33. }
    34. }
    35.  
    36. }
    37. }
    38.  
    39.  
    40. public boolean onCommand(CommandSender sender, Command cmd,
    41. String commandLabel, String[] args) {
    42. return false;
    43. }
    44. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  16. Offline

    Ghilliedrone

    AgentJayCraft
    Make sure you import if available. Also, try with nothing in the onEnable but
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, this);


    You forgot to add Listener on line 14

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
    AgentJayCraft likes this.
  17. Offline

    AgentJayCraft

    Is this what it should look like
    Code:java
    1. package me.ggames62.PoP;
    2.  
    3. import org.bukkit.Bukkit;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Entity;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class PoP extends JavaPlugin implements Listener{
    15. public static PoP plugin;
    16.  
    17. public void onEnable() {
    18. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    19. }
    20.  
    21. @EventHandler
    22. public void onEntityByDamagerEntity(EntityDamageByEntityEvent event){
    23. Entity e = event.getDamager();
    24.  
    25. if(e instanceof Player) {
    26. Player player = (Player) e;
    27.  
    28. for(Player online : Bukkit.getOnlinePlayers()) {
    29. if(online.getName() != player.getName()) {
    30. online.hidePlayer(player);
    31. }
    32. }
    33.  
    34. }
    35. }
    36.  
    37.  
    38. public boolean onCommand(CommandSender sender, Command cmd,
    39. String commandLabel, String[] args) {
    40. return false;
    41. }
    42. }
     
  18. Offline

    Ghilliedrone

    AgentJayCraft
    Looks good ;). I tested it and no errors in the code
     
    AgentJayCraft likes this.
  19. Offline

    AgentJayCraft

    ok so I am going to test it on my server but I have no one to test it one. If I give you the ip can u help me test it?
     
  20. Offline

    Ghilliedrone

  21. Offline

    AgentJayCraft

    solarcraft.sytes.net

    @Ghillliedrone THANNKS SOOOOOOO MUCHHHHHHHHHHHHH !!!! the .getentity worked!!!!! thanks a million!!!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page