Solved help with biome plugin

Discussion in 'Plugin Development' started by NadDeMan, Nov 3, 2020.

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

    NadDeMan

    i want a plugin that detects when you enter a biome, and send you a title that says welcome to (biome)!
    or something like that, but Im really new at java, so i need your help...
    what's wrong with my code and how to fix it?
    btw, ignore the BiomeCommand...
    its another thing i have in the plugin.

    Code:
    package me.NadDeMan.BiomePlugin;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    
    import me.NadDeMan.BiomePlugin.commands.BiomeCommand;
    
    public class Main  extends JavaPlugin implements Listener  {
        
        
        public void onEnable(){
            new BiomeCommand(this);
            runnable();
        }
    
    
        public void runnable() {
            new BukkitRunnable(){
    
                @Override
                public void run() {
               
                Player p  = (Player) Bukkit.getOnlinePlayers();
                       
                String Loc = String.valueOf(p.getLocation().getBlock().getBiome()) + "";
                System.out.println(Loc);
                for(Loc.equals(String.valueOf(p.getLocation().getBlock().getBiome()));;){
                    p.sendTitle("Welcome to",String.valueOf(p.getLocation().getBlock().getBiome()) , 1, 20, 1);
                    Loc = String.valueOf(p.getLocation().getBlock().getBiome()) + "";
    
                   
                    }
                }
            };
        }
    }
    
     
  2. Offline

    timtower Administrator Administrator Moderator

    @NadDeMan You make the runnable, but you never start it.
     
  3. Offline

    NadDeMan

    is that my ONLY mistake? really?
    so how do I fix it?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @NadDeMan After you make the instance you call runTaskTimer(this, <time between checks)
    And probably not the only mistake.
    This is the one that is hiding the others though.

    Have you considered using a PlayerMoveEvent though?
     
  5. Offline

    NadDeMan

    Yes, but I couldn't do it.
    I'm really new at this whole plugin thingy, and I really need help.
    can you help me use PlayerMoveEvent?
    btw, I tried to do RunTaskTimer but it said it is deprecated...
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    NadDeMan

    okay, so the PlayerMoveEvent worked, but my code inside the onMove isn't working.
    Code:
    @EventHandler
        public void onMove(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            String Loc = p.getLocation().getBlock().getBiome() + "";
            if(!Loc.equals(String.valueOf(p.getLocation().getBlock().getBiome()))){
                p.sendTitle("Welcome to",String.valueOf(p.getLocation().getBlock().getBiome()) , 1, 20, 1);
                Loc = p.getLocation().getBlock().getBiome() + "";
    
              
                }
    btw, I took a little break for about 5 days...
     
  8. Offline

    timtower Administrator Administrator Moderator

    @NadDeMan You do realize that you can compare getBiome() values with == right?
     
  9. Offline

    NadDeMan

    so I can do this?
    if(Loc !=String.valueOf(p.getLocation().getBlock().getBiome())){
    p.sendTitle("Welcome to",String.valueOf(p.getLocation().getBlock().getBiome()) , 1, 20, 1);
    Loc = p.getLocation().getBlock().getBiome() + "";


    }
    I'm sorry for not understanding...
    I'm really noob at java.
     
  10. Offline

    timtower Administrator Administrator Moderator

    @NadDeMan p.getLocation().getBlock().getBiome()!=p.getLocation().getBlock().getBiome()
    No need for strings.
    And Enums have a .name() method to get a string.
     
  11. Offline

    NadDeMan

    but I want to check if the player has entered a different biome...
    will that solve it?
     
  12. Offline

    timtower Administrator Administrator Moderator

    @NadDeMan See the first check.
    And have you considered using the old and new position?
    The event has a from() and to() method.
     
  13. Offline

    NadDeMan

    no... cause I don't know how to do that.
    can you help me doing it?
     
  14. Offline

    timtower Administrator Administrator Moderator

    @NadDeMan You have a from() and to() method.
    Get the biomes from there.
    Compare those.
     
  15. Offline

    NadDeMan

    Ohhhhh i get it

    Thank you!!! it worked!!!

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

Share This Page