Solved no obligatory to import other plugin

Discussion in 'Plugin Development' started by maniac058, May 1, 2015.

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

    maniac058

    Hello,
    I'm french so sorry for mistakes :)

    I create a plugin that is called "Bloody Effect" which goal to simulate injury when players pvp, or otherwise.
    And as some server uses vanish, so the plugin makes sure to adjust when the player is vanish is that the particle is not displayed.

    The problem, I can not ensure that we not require that either install vanish. I can make it work with vanish but if I remove the plugin vanish, I have to change the code.

    My code :
    Code:
    package fr.maniac058.BloodEffect;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.kitteh.vanish.staticaccess.VanishNoPacket;
    import org.kitteh.vanish.staticaccess.VanishNotLoadedException;
    
    
    
    @SuppressWarnings("deprecation")
    public class BloodEffectPl implements Listener {
       
        //public String VanishNoPacketPl = "PlDisable";
        public BloodEffect pl;
    
        public BloodEffectPl(BloodEffect pl) {
            this.pl = pl;
        }
       
    
        @EventHandler
        public void onEffetSanguin1(EntityDamageByEntityEvent e) {
            if(this.pl.getServer().getPluginManager().getPlugin("VanishNoPacket") != null){
               
            }
            else
            {
                Bukkit.broadcastMessage("NON");
            }
        }
       
        @EventHandler
        public void onEffetSanguin(EntityDamageByEntityEvent e) throws VanishNotLoadedException {
           
            if(this.pl.getServer().getPluginManager().getPlugin("VanishNoPacket") != null){
                if(VanishNoPacket.isVanished(""+e.getDamager().getName()+"")){
                   
                }
                else
                {
                    Entity entity = e.getEntity();
                    Location entityloc = entity.getLocation();
                    if((entity.getType() != EntityType.ITEM_FRAME)) {
                        entity.getWorld().playEffect(entityloc, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                   
                }
                //String VanishNoPacketPl = "PlEnable";
                //Bukkit.broadcastMessage(""+e.getDamager().getName()+"");
            }
            else
            {
                //String VanishNoPacketPl = "PlDisable";
                //Bukkit.broadcastMessage("NON");
                //Entity entity = e.getEntity();
                //Location entityloc = entity.getLocation();
                //if((entity.getType() != EntityType.ITEM_FRAME)) {
                //    entity.getWorld().playEffect(entityloc, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                //}
            }
        }
        
    }
    So, my error in the console without the vanish plugin

    [​IMG]

    Is my plugin latency risk of certain player ?

    Thank you :)
     
  2. Offline

    Konato_K

    @maniac058 You're trying to register an event handler that uses a class in a plugin that does not exist yet.

    Make sure you have VanishNoPacket in your plugins and add the dependency in the plugin.yml to make sure VanishNoPacket loads before your plugin.
     
  3. Offline

    maniac058

    But I want to make varnish is not necessary.

    I want made sure that operate with and without vanish.
    Exemple Public with public and public without vanish.
     
  4. Offline

    Konato_K

    @maniac058 I don't think what you wrote makes much sense.

    Anyway, then just add it as a soft dependency (still insures it loads after VanishNoPacket) and only try to register your event handlers if VanishNoPacket is loaded.
     
  5. Offline

    maniac058

    My plugin works when Vanish is present.

    But I wish it also works without the plugin vanish.
    Example, to a condition. if plugin vanish else without plugin vanish.
     
  6. Offline

    Avygeil

    @maniac058 In your plugin.yml, add Vanish as a soft dependency. I'm guessing isVanished is a static method, so in your onEnable, check if Vanish is installed the same way you currently do. Store the result as a boolean. If both this boolean and isVanished are true, return and don't show the effects.

    En gros, si tu l'ajoutes en soft dependency, Bukkit le chargera avant ton plugin seulement si il existe. Quand tu actives ton plugin tu fais pareil (le getPlugin != null) et tu le mets dans genre isVanishLoaded. Puis tu fais un truc comme ça :
    Code:
    @EventHandler
    public void onEffetSanguin(EntityDamageByEntityEvent e) throws VanishNotLoadedException {
        if (isVanishLoaded && VanishNoPacket.isVanished(e.getDamager().getName())) return;
        // show effects
    }
    Et tu peux faire pareil pour n'importe quel autre cas. Un truc cool avec Java c'est qu'il est typé dynamiquement. D'abord Java voit la condition, puis il regarde "isVanishLoaded". Si c'est false, il sort de la condition: il n'a pas besoin d'évaluer la deuxième partie de la condition puisque la première est déjà fausse. Donc il ne verra jamais le VanishNoPacket si il n'est pas installé. Or si il est installé et que ton joueur est vanish, tu sorts de l'event donc tu ne montres pas l'effet. :)
     
  7. Offline

    maniac058

    I think a moderator delete my message :p

    @Avygeil

    -- ENGLISH --
    My goal is that the plugin also works without the plugin vanish. Make vanish if is present then it must be the effect for everyone. There must be a way to do without two plugin?

    -- FRANCAIS --
    Mon but est que le plugin fonctionne aussi sans le plugin vanish. Faire que si vanish est présent alors il doit faire l'effet pour tout le monde. Il doit bien avoir un moyen de faire sans faire deux plugin ?

    Code:
    @EventHandler
        public void onEffetSanguin(EntityDamageByEntityEvent e) throws VanishNotLoadedException {
            Entity entity = e.getEntity();
            if (isVanishLoaded && VanishNoPacket.isVanished(e.getDamager().getName())) return;
            // show effects
            if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
            }
            else if(e.getCause().equals(DamageCause.FIRE)){
                Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
            }
        }
    isVanishLoaded is not working
     
    Last edited: May 1, 2015
  8. Offline

    mythbusterma

    @Avygeil

    If you post in another language, please write it again in English.
     
  9. Offline

    maniac058

  10. Offline

    Avygeil

    @mythbusterma Erm... That's what I did in the beginning of the post.

    @maniac058 Yeah I understood your goal and told you how to work it out by detecting if Vanish is installed. What do you mean by "isVanishLoaded" doesn't work? Did you do detect it in onEnable? Please show the full code.

    Comment ça marche pas? Tu peux être plus précis? Est-ce que tu peux copier tout ton code et particulièrement ton onEnable?
     
  11. Offline

    maniac058

    @Avygeil
    So, the code is correct :)
    Error by me :p

    But there to other error.
    Code:
    public class BloodEffectPl implements Listener {
    
        public BloodEffect pl;
    
        public BloodEffectPl(BloodEffect pl) {
            this.pl = pl;
        }
    
        public boolean isVanishLoaded() {
            if(this.pl.getServer().getPluginManager().getPlugin("VanishNoPacket") != null) {
                return true;
            }
            else
            {
                return false;
            }
        }
    
        @EventHandler
        public void onEffetSanguin(EntityDamageByEntityEvent e) throws VanishNotLoadedException {
            Entity entity = e.getEntity();
            if (isVanishLoaded() && VanishNoPacket.isVanished(e.getDamager().getName())) return;
    
            if(entity.getType() != EntityType.ITEM_FRAME) {
                Bukkit.broadcastMessage(""+entity.getType());
                if((entity.getType() != EntityType.CHICKEN) || (entity.getType() != EntityType.PIG) || (entity.getType() != EntityType.WOLF) || (entity.getType() != EntityType.SHEEP) || (entity.getType() != EntityType.SPIDER)) {
                    if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                    else if(e.getCause().equals(DamageCause.FIRE)){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                }
                else
                {
                    Bukkit.broadcastMessage("2TEST");
                    if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                    else if(e.getCause().equals(DamageCause.FIRE)){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                }
            }
        }
    }
    Code:
    package fr.maniac058.BloodEffect;
    
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    public class BloodEffect extends JavaPlugin implements Listener{
            public void onEnable(){
                    System.out.println("Enable plugin");
                    PluginManager pm = getServer().getPluginManager();
                    pm.registerEvents(new BloodEffectPl(this), this); 
            }
            public void onDisable(){
                    System.out.println("Disable plugin");   
            }
    }
    if to attack sheep, my code through " if((entity.getType() != EntityType.CHICKEN) || (entity.getType() != EntityType.PIG) || (entity.getType() != EntityType.WOLF) || (entity.getType() != EntityType.SHEEP) || (entity.getType() != EntityType.SPIDER)) {"
    so the first and not the second. Why?

    The plugin depency the vanish, but i want no depency the vanish and also operates without.

    There a way to view the particles only for persones that activates the particles in their minecraft?

    --French--

    Quand j'attaque un mouton, je passe par la boucle " if((entity.getType() != EntityType.CHICKEN) || (entity.getType() != EntityType.PIG) || (entity.getType() != EntityType.WOLF) || (entity.getType() != EntityType.SHEEP) || (entity.getType() != EntityType.SPIDER)) {"
    Et non par l'autre boucle pourquoi ?

    Ensuite, je voudrais si c'est possible de faire en sorte qu'il ne soit pas en dépendance avec Vanish. Qu'il fonctionne avec et sans vanish.

    Et aussi, faire en sorte pour les joueurs qui voit pas les particules dans leur options, que sa ne s'affiche pas.

    EDIT :


    EN: I advanced in the code, the only problem is the condidation that allows me to know if I hit an animal 1 block or two block . ( size )

    FR: J'ai avancé dans le code, le seul problème vient de la condidation qui me permet de savoir si je tape sur un animal à deux bloc ou 1 bloc. (taille)

    Code:
    public class BloodEffectPl implements Listener {
      
        public BloodEffect pl;
    
        public BloodEffectPl(BloodEffect pl) {
            this.pl = pl;
        }
      
        public boolean isVanishLoaded() {
            if(this.pl.getServer().getPluginManager().getPlugin("VanishNoPacket") != null) {
                return true;
            }
            else
            {
                return false;
            }
        }
      
        @EventHandler
        public void onEffetSanguin(EntityDamageByEntityEvent e) throws VanishNotLoadedException {
            Entity entity = e.getEntity();
            if (VanishNoPacket.isVanished(e.getDamager().getName())) return;
            //Bukkit.broadcastMessage(""+entity.getType());
            if(entity.getType() != EntityType.ITEM_FRAME) {
              
                if(!(entity instanceof Chicken)
                        | !(entity instanceof Pig)
                        | !(entity instanceof Wolf)
                        | !(entity instanceof Sheep)
                        | !(entity instanceof Spider)) {
                    /*
                     *
                     *
                     * MOB 2 bloc
                     *
                     *
                     */
                    Bukkit.broadcastMessage("1er");
                    if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                    else if(e.getCause().equals(DamageCause.FIRE)){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                }
                else
                {
                    /*
                     *
                     *
                     * MOB 1 bloc
                     *
                     *
                     */
                    Bukkit.broadcastMessage("2eme");
                    if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                    else if(e.getCause().equals(DamageCause.FIRE)){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                }
            }
        }
    }
     
    Last edited: May 2, 2015
  12. Offline

    Avygeil

    @maniac058 Why do you keep asking how to make Vanish optional? I gave you the answer in my first response and your code was fine until you removed isVanishLoaded(). The Vanish statement will not even be evaluated if Vanish is not installed, so you don't have to worry about it. Though, now that you mention effects on mobs, you also have to check if the damaged entity is a player. Also I think you meant to check if the damaged player is vanished, and not the damager. Keep this in your method's head:
    Code:
    if(e.getEntityType() == EntityType.PLAYER && isVanishLoaded() && VanishNoPacket.isVanished(e.getEntity().getName())) return;
    Your other problem is also a problem with logic. I advice you to think aloud what your conditions will do for all states possible, and all will be clear. For example, when you hit a sheep, "entity instanceof Chicken" is false. So "!(entity instanceof Chicken)" is true. Your condition is made of OR's: if (cond1 || cond2 || ...). In such conditions, if anything is true, you will exit the checks. This explains why when you hit a sheep you go through the first part.

    You should really work out your logic. This is fundamental to achieve even the simplest things as you can see. You will also avoid having duplicated code like in your method. I will help you with the flow, but please write it in Java yourself:
    Code:
    if a player is being hit and vanish is installed and the player is vanished // This is just what I said above.
        return
    
    // Since it looks like you want to filter some DamageCause, you do it here
    if the cause is causeA OR causeB OR causeC // This means if (causeA || causeB || causeC) and not what you did
        return
    
    // From here, we KNOW that the particles will be displayed, so let's not duplicate the code. Use variables to control the state instead.
    // Apparently the only thing that changes is getY(), so let's write that out :
    if the entity is typeA OR typeB OR typeC
        y = getY() // 1 block tall
    else
        y = getY() + 1 // 2 blocks tall
    
    // Show the particles with your code above, but use the y variable
    new location with the entity's X, the Y defined above (NOT the entity's), and the entity's Z
    play effect
    If you didn't understand the above, then I recommend learning more and reading more source code. Since you asked how to make Vanish optional in every single post, I took it as you were very confused with the logic within conditions.

    Tu m'en voudras pas de ne pas traduire en français, c'est un peu long. :) Ils soulent aussi à obliger à parler leur langue pourrie.
     
  13. Offline

    maniac058

    My code is functional :)
    A person is come help me ;)

    I still have a problem with a condition :p

    Code:
    @EventHandler
        public void onEffetSanguin(EntityDamageByEntityEvent e) throws VanishNotLoadedException {
            Entity entity = e.getEntity();
            if (VanishNoPacket.isVanished(e.getDamager().getName())) return;
            //Bukkit.broadcastMessage(""+entity.getType());
            if(entity.getType() != EntityType.ITEM_FRAME) {
              
                if(!(entity instanceof Chicken)
                        || !(entity instanceof Pig)
                        || !(entity instanceof Wolf)
                        || !(entity instanceof Sheep)
                        || !(entity instanceof Spider)) {
                    /*
                     *
                     *
                     * MOB 2 bloc
                     *
                     *
                     */
                    Bukkit.broadcastMessage("1er");
                    if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                    else if(e.getCause().equals(DamageCause.FIRE)){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                }
                else
                {
                    /*
                     *
                     *
                     * MOB 1 bloc
                     *
                     *
                     */
                    Bukkit.broadcastMessage("2eme");
                    if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                    else if(e.getCause().equals(DamageCause.FIRE)){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                }
            }
        }
    If, to attack sheep, my code pass per Bukkit.broadcastMessage("1er"); and no per Bukkit.broadcastMessage("2eme");.

    EDIT :

    Thank you for your help :)
    My problems is solved ;)

    Code:
    @EventHandler
        public void onEffetSanguin(EntityDamageByEntityEvent e) throws VanishNotLoadedException {
            Entity entity = e.getEntity();
            if (VanishNoPacket.isVanished(e.getDamager().getName())) return;
            //Bukkit.broadcastMessage(""+entity.getType());
            if(entity.getType() != EntityType.ITEM_FRAME) {
               
                if(!(entity instanceof Chicken)
                        && !(entity instanceof Pig)
                        && !(entity instanceof Wolf)
                        && !(entity instanceof Sheep)
                        && !(entity instanceof Spider)) {
                    /*
                     *
                     *
                     * MOB 2 bloc
                     *
                     *
                     */
                    Bukkit.broadcastMessage("1er");
                    if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                    else if(e.getCause().equals(DamageCause.FIRE)){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY() + 1, entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                }
                else
                {
                    /*
                     *
                     *
                     * MOB 1 bloc
                     *
                     *
                     */
                    Bukkit.broadcastMessage("2eme");
                    if(e.getCause().equals(DamageCause.ENTITY_ATTACK) || (e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) || (e.getCause().equals(DamageCause.PROJECTILE)) || (e.getCause().equals(DamageCause.FIRE_TICK))){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                    else if(e.getCause().equals(DamageCause.FIRE)){
                        Location nl = new Location(entity.getWorld(), entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ());
                        entity.getWorld().playEffect(nl, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
                    }
                }
            }
        }
     
    Last edited: May 2, 2015
  14. Offline

    Avygeil

    Lmao ok... That will teach me not to write damn essays :rolleyes:
     
Thread Status:
Not open for further replies.

Share This Page