Solved Can someone check for errors?

Discussion in 'Plugin Development' started by Brevoort, Oct 21, 2016.

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

    Brevoort

    So I'm making a plugin which detects when a player gets an achievement, and it gives them an item randomly from a list I'm making. I have exported it to my server, but I'm not getting any achievements or messages. This might be with my code, or it might be with my server.

    My Main Class:
    Code:
    package me.themedieval;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Medfre1 extends JavaPlugin{
      
        public void onEnable() {
            new EventListener(this);
        }
      
        public void onDisable(){
          
        }
    
    
    }

    My Listener Class:
    Code:
    package me.themedieval;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    
    public class EventListener implements Listener{
        public EventListener(Medfre1 plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
        @EventHandler
        public void aListener(PlayerAchievementAwardedEvent event) {
            Player player = event.getPlayer();
            double number = Math.random();
            if(number <= 0.34) {
                player.sendMessage(ChatColor.GREEN + "You won a prize for completing an achievement!");
            } else if(number <= 0.67) {
                player.sendMessage(ChatColor.RED + "You won a prize for completing an achievement!");
              
            } else {
                player.sendMessage(ChatColor.BLUE + "You won a prize for completing an achievement!");
            }
        }
    }
    



    So far I have made it only send messages as a test, however I don't see any messages.

    I do have achievement announcement on in my server but it doesn't seem to work, and I need to delete player data but when I deleted userdata I still have all my gear/perms.
     
  2. Offline

    RenditionsRule

    @Brevoort
    It doesn't look like you registered your events correctly. Try the registerEvents() method in onEnable?
     
  3. Offline

    Brevoort

    How would I use this method?
     
  4. Offline

    RenditionsRule

    @Brevoort
    Bukkit#getPluginManager()

    You should be able to handle it from there?
     
  5. Offline

    Brevoort

    One more question!
    How could I make it so that when it detects the achievement, instead of just sending a message, it runs a command. (I know I could just make it give the player an item, however I want to make it run a command like /pay player 1000 or something like that.
     
  6. Offline

    theone1000

    Code:
    dispatchCommand(CommandSender sender, String commandLine);
     
    Brevoort likes this.
  7. Offline

    Brevoort

    I tried using this but it gives me errors and asks me to create constants for all of those.
     
  8. Offline

    theone1000


    Code:
    Bukkit.dispatchcommand(Bukkit.getconsolesender(), "yourcommand")
    
    example below,
    
    Bukkit.dispatchcommand(Bukkit.getconsolesender(), "say hello world!")
    
    
    will execute '/say hello world!' from console 
     
  9. Offline

    Brevoort

    Thanks this seems to work however using
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player + " minecraft:diamond 1");
    results in the console saying "player not found."

    I'm defining player as Player player = event.getPlayer();
     
  10. Offline

    theone1000

    That's because you're getting the player itself not the players name use player.getName()
     
    Brevoort likes this.
  11. Offline

    Brevoort

    thanks
     
Thread Status:
Not open for further replies.

Share This Page