Custom Portal

Discussion in 'Plugin Development' started by Jacob00524, Dec 10, 2019.

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

    Jacob00524

    package com.divisionactivate.factions.commands;
    import java.util.Collection;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scheduler.BukkitScheduler;
    public class portal extends BukkitRunnable {
    public void main() {
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    @Override
    public void run() {
    // Do something
    System.out.println("test1");
    Collection<? extends Player> player = Bukkit.getOnlinePlayers();
    Location Officemin = new Location(Bukkit.getWorld("world"), -143,168,68);
    Location officemax = new Location(Bukkit.getWorld("world"), -145,170,70);
    for(Player p : player) {
    if(p.getWorld() == Bukkit.getWorld("world")) {
    if(p.getLocation().getX() <= Officemin.getX() && p.getLocation().getX() >= officemax.getX()) {
    if(p.getLocation().getZ() <= Officemin.getZ() && p.getLocation().getZ() >= officemax.getZ()) {
    if(p.getLocation().getY() <= Officemin.getY() && p.getLocation().getY() >= officemax.getY()) {
    p.teleport(Bukkit.getWorld("office").getSpawnLocation());
    }
    }
    }
    }
    }
    }
    }, 0L, 0L);
    }
    }
     
    Last edited: Dec 10, 2019
  2. Offline

    timtower Administrator Administrator Moderator

    @Jacob00524 They will never be at that block.
    Check a range instead.
    And just use a BukkitRunnable instead of a commandblock.
     
  3. Offline

    Jacob00524

    When i press f3 in game and look a t my block it shows that exact cord. Thats why i did block pos and not normal pos.

    I might sound a little mean but i promise i am grateful for your fast reply and useful.
     
    Last edited: Dec 10, 2019
  4. Offline

    timtower Administrator Administrator Moderator

    @Jacob00524 Don't see how telling somebody where you come from help anybody. Hi Canadian, I am Timtower.

    The block below you has that coordinate. Your feet are on top of that block.
     
    CraftCreeper6 and Jacob00524 like this.
  5. Offline

    Jacob00524

    I have added the bucketRunnable, but now i have two more errors.
    First one is on Line 12
    "public class portal extends BukkitRunnable {"
    Saying "The type portal must implement the inherited abstract method Runnable.run()"

    Next is Line 16,

    "scheduler.scheduleSyncRepeatingTask(this, new Runnable() {"
    saying "The type portal must implement the inherited abstract method Runnable.run()"
     
  6. Offline

    KarimAKL

    @Jacob00524 You need to override the void method run().
     
  7. Offline

    Jacob00524

    I have a
    Code:
    @Override
                public void run() {
    already is this wrong?
     
  8. Offline

    KarimAKL

    @Jacob00524 Looks correct to me, do you still have the error? If so, could you paste the whole class?
     
  9. Offline

    Jacob00524

    Code:
    package com.divisionactivate.factions.commands;
    
    
    import java.util.Collection;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_14_R1.Overridden;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scheduler.BukkitScheduler;
    
    public class portal extends BukkitRunnable {
    
        public void main() {
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
               
                @Overridden
                public void run() {
                    // Do something
                    System.out.println("test1");
                     Collection<? extends Player> player = Bukkit.getOnlinePlayers();
                     Location Officemin = new Location(Bukkit.getWorld("world"), -143,168,68);
                     Location officemax = new Location(Bukkit.getWorld("world"), -145,170,70);
                     for(Player p : player) {
                         if(p.getWorld() == Bukkit.getWorld("world")) {
                             if(p.getLocation().getX() <= Officemin.getX() && p.getLocation().getX() >= officemax.getX()) {
                                 if(p.getLocation().getZ() <= Officemin.getZ() && p.getLocation().getZ() >= officemax.getZ()) {
                                     if(p.getLocation().getY() <= Officemin.getY() && p.getLocation().getY() >= officemax.getY()) {
                                         p.teleport(Bukkit.getWorld("office").getSpawnLocation());
                                     }
                                 }
                             }
                         }
                     }
                }
            }, 0L, 0L);
        }
    
    }
     
  10. Offline

    KarimAKL

    @Jacob00524 My bad on the "paste the whole class" part, you already did that in the OP. :7

    The reason you get that error is because your class "portal" extends BukkitRunnable but, you don't have the run() method inside that class.

    Fixes:
    1. Don't make "portal" extend BukkitRunnable.
    2. The annotation "Overridden" should be "Override"
    3. I don't think you can make the scheduler run every 0 ticks, change it to 1.
     
Thread Status:
Not open for further replies.

Share This Page