Solved Trying to Cast runTaskTimer

Discussion in 'Spigot Plugin Development' started by Warriorn, Jul 14, 2019.

  1. I haven't been programming for so long and casting is pretty new to me but I'm trying to run a BukkitRunnable outside the Main class and I don't know how to. Any help at all would be appreciated!

    Code: (The important part)
    Listener:
    Code (Text):
    Core core;
     

        public BerserkerMovment(Core core)
        {
            this.core = core;
        }
    Code (Text):
     }.runTaskTimer((Core) core, 0, 1);
    Main:
    Code (Text):
    public static Core plugin;

    Bukkit.getPluginManager().registerEvents(new BerserkerMovment(this), this);
    All of theListener:
    Code (Text):
         Core core;
     
        int count = 0;
     
        public BerserkerMovment(Core core)
        {
            this.core = core;
        }

    @EventHandler
          public void BerserkerGravityOrb(PlayerMoveEvent e){
              Player player = e.getPlayer();
              Rank rank = Core.getFileManager().getRank(player);
           
           
              if (rank.equals(Rank.BERSERKER)|| rank.equals(Rank.BADBERSERKER)) {
              if (player.isSneaking() && player.isOnGround())
              {
                 if (CM.checkCooldown(player)) {
                  ArmorStand gravOrb = (ArmorStand) e.getPlayer().getWorld().spawnEntity(e.getPlayer().getLocation().add(0.5,0.5,0.5), EntityType.ARMOR_STAND);
                  gravOrb.setVisible(false);
                  gravOrb.setAI(false);
                  gravOrb.setGravity(false);
                  gravOrb.setCustomName("GRAV_ORB");
                  gravOrb.setCustomNameVisible(false);
                  count = 0;
                  new BukkitRunnable() {

                      @Override
                      public void run() {
                          if(count>= 15){
                              gravOrb.remove();
                              this.cancel();
                          } else {
                              for(Entity ent : gravOrb.getNearbyEntities(5, 5, 5)){
                                  if (ent instanceof Player)
                                  {
                                      Rank rankE = Core.getFileManager().getRank((Player) ent);
                                   
                                      if (e.getPlayer().getWorld().getName().equals("world"))
                                      {
                                   
                                          if (rank.equals(Rank.BERSERKER))
                                          {
                                       
                                              if (rankE.equals(Rank.BADASSASIN) || rankE.equals(Rank.BADBERSERKER) || rankE.equals(Rank.BADPRIEST))
                                              {
                                                  ent.setVelocity(ent.getVelocity().clone().add(gravOrb.getLocation().clone().toVector().subtract(ent.getLocation().clone().toVector()).multiply(0.08)));
                                              }
                                          } else {
                                              if (rank.equals(Rank.BADBERSERKER)) {
                                                  if (rankE.equals(Rank.ASSASIN) || rankE.equals(Rank.BERSERKER) || rankE.equals(Rank.PRIEST))
                                                  {
                                                      ent.setVelocity(ent.getVelocity().clone().add(gravOrb.getLocation().clone().toVector().subtract(ent.getLocation().clone().toVector()).multiply(0.08)));
                                                  }
                                          }
                                                  }
                                      } else {
                                          // Fix Clan stuff for CW (CLAN WAR)
                                      }
                                  } else {
                                      // On Monster
                                      ent.setVelocity(ent.getVelocity().clone().add(gravOrb.getLocation().clone().toVector().subtract(ent.getLocation().clone().toVector()).multiply(0.08)));
                                  }
                               
                               
                              }
                          }
                     
                          count++;
                      }
                 
                  }.runTaskTimer((Core) core, 0, 1);
              } else { return; }
              }
              }
          }
     
    #1 Warriorn, Jul 14, 2019
    Last edited: Jul 14, 2019
  2. You are doing kind of great, there is no need to cast it on there, so you shouldnt have any problem

    The plugin variable on your main class is unnecesary
     
    • Friendly Friendly x 1
  3. But the code won't work in the Listener. If I put it in the Main there is no problem.
     
  4. Can you be more specific with "Wont work"? Error? Not firing?
     
    • Agree Agree x 1
  5. Or not... The code works in another project but not this one need to do some further testing thanks for the help!
     
  6. In short I'm trying to create a gravity orb that pulls the nearby players towards the user for a short time
     
  7. With further testing, I can't get the event to load at all... All other events work fine. Where i put it doesn't matter really weird
     
  8. Send your full classes including the imports.
     
    • Agree Agree x 1
  9. I fixed the problem "sort of". I believe something was wrong in my class that manages cooldowns. I manage to solve it but it's not pretty. Thanks for all the help!!