[ solved] Plugin is not working, no errors in console

Discussion in 'Spigot Plugin Development' started by 1337Caleb, Jul 10, 2015.

  1. I made a simple plugin where if you use a fishing rod on a player, aslong as it attached to them it gives slowness. But it does not work, nothing happens.

    Code:

    package caleb.lasho.main;

    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerFishEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class Main extends JavaPlugin {
    @Override
    public void onEnable(){
    this.getLogger().info("Lasso started");
    }
    public void onDisable(){
    this.getLogger().info("Lasso stopped");
    }
    @EventHandler
    public void onPlayerFish(PlayerFishEvent event){
    Player player = event.getPlayer();
    if(event.getCaught() != null){
    Entity caught = event.getCaught();
    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 2));


    }else{
    return;
    }
    if(event.getCaught() == null){
    player.removePotionEffect(PotionEffectType.SLOW);
    }
    }

    }
     
  2. Creeoer

    Supporter

    JavaPlugin doesn't implement listener.
    if(event.getCaught() != null){
    Entity caught = event.getCaught();
    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 2));


    }else{
    return;
    }

    You're saying that if the caught entity is null return, stop everything. Meaning your second block of code will essentially never be called.
     
  3. Hows this?

    package caleb.lasho.main;

    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerFishEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class Main extends JavaPlugin implements Listener {
    @Override
    public void onEnable(){
    this.getLogger().info("Lasso started");
    }
    public void onDisable(){
    this.getLogger().info("Lasso stopped");
    }
    @EventHandler
    public void onPlayerFish(PlayerFishEvent event){
    Player player = event.getPlayer();
    if(event.getCaught() != null){
    Entity caught = event.getCaught();
    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 2));


    }else{
    player.removePotionEffect(PotionEffectType.SLOW);
    return;
    }
    }

    }
     
  4. Creeoer

    Supporter

    You don't have to return on that last else statement. Just add the line @ClickPT suggested you to the onEnable. And if you're trying to give potion effects to the entity that was caught you aren't doing that. You should first be checking if the caught entity is even a player. Once you know that you can apply the potion effects.
     
  5. Does this look good?
    package caleb.lasho.main;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerFishEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class Main extends JavaPlugin implements Listener {
    @Override
    public void onEnable(){
    this.getLogger().info("Lasso started");
    Bukkit.getPluginManager().registerEvents(this, this);
    }
    public void onDisable(){
    this.getLogger().info("Lasso stopped");
    }
    @EventHandler
    public void onPlayerFish(PlayerFishEvent event){
    Player player = event.getPlayer();
    if(event.getCaught() != null){

    Entity caught = event.getCaught();
    if(caught instanceof Player){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 2));
    }

    }else{
    player.removePotionEffect(PotionEffectType.SLOW);
    return;
    }
    }

    }
     
    • Like Like x 1
  6. That looks good. If it works you need to add [Solved] to the title of your thread
     
  7. latiku

    Supporter

    If it still doesn't work, I'd like to have your plugin.yml
     
  8. Code (Text):
    name: Plugin Name
    description: Plugin Discription
    version: 1.0
    main: your.main.class
    replace "plugin name", etc. with your real values.

    if you have commands for your plugin add them under description like this:
    Code (Text):
    commands:
      commandname:
        description: what your command does
    Replace "commandname" with what your command actually is.
     
  9. Your code as is now will give slowness to the player who is holding the fishing rod.
     
  10. Should errors still occur, please ask further.
     
  11. Final code, and it works

    package caleb.lasho.main;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerFishEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class Main extends JavaPlugin implements Listener {
    @Override
    public void onEnable(){
    Bukkit.getPluginManager().registerEvents(this, this);
    this.getLogger().info("Lasso started");

    }
    public void onDisable(){
    this.getLogger().info("Lasso stopped");
    }
    @EventHandler
    public void onPlayerFish(PlayerFishEvent event){
    final Player player = event.getPlayer();
    if (event.getCaught() instanceof Player) {
    final Player caught = (Player) event.getCaught();
    if (player.getItemInHand().getType() == Material.FISHING_ROD) {
    caught.sendMessage(ChatColor.RED + "You have been wrangled!");
    caught.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 2));
    }
    }
    }
    {

    }
    }