Not working Event

Discussion in 'Spigot Plugin Development' started by zozidalom, May 31, 2016.

  1. http://pastebin.com/6b5Hr7jM

    My event does not work some way. I am gonna check if a msg contains a string part and if yes give a player a book but something is wring :( Please help me!
     
  2. Hello.. you must add this
    Code (Text):
    Bukkit.getPluginManager().registerEvents(this, this);
    in the "public void onEnable()"
     
  3. Hy I have it :D In a diferent class.
    getServer().getPluginManager().registerEvents(new plugin.zozidalom.risingempire.Events(this), this);
     
  4. in your Events class must the main class import
    Code (Text):
    private Main plugin;
     
      public Events(Main main)
      {
        this.plugin = main;
      }
     
  5. Also have it
    private Main main;


    public Events(Main main) {
    this.main = main;
    }
     
  6. Do you have 'implements Listener'?
    A little more context would be helpful here. Can you post your complete classes?
     
  7. Does nobody read error messages anymore?
    ItemStack and BookMeta are different things.
    Maybe try
    Code (Text):
    yourbookmeta = (BookMeta) youritemstack.getItemMeta();
     
  8. @EventHandler
    public void onPlayerCommandPreocess(PlayerCommandPreprocessEvent e) {
    if(e.getMessage().startsWith("/login")) {
    Player p = e.getPlayer();
    if(p.getName().equalsIgnoreCase("Crankiee")) {
    ItemStack b = new ItemStack(Material.BOOK, 1);ItemMeta i = b.getItemMeta();
    BookMeta bm = (BookMeta) b.getItemMeta();
    if(main.getServer().getPlayer("zozidalom").isOnline() == true) {
    main.getServer().getPlayer("zozidalom").getEnderChest().setItem(1, b);
    e.getPlayer().sendMessage("s");
    }
    }
    }
    }

    Yes I now but not working :(
     
  9. Code (Text):
    @EventHandler
    public void onPlayerCommandPreocess(PlayerCommandPreprocessEvent e) {
    Bukkit.broadcastMessage("Hooray! Event fired!");
    if(e.getMessage().startsWith("/login")) {
    Bukkit.broadcastMessage("We got someone loggin' in!");
    Player p = e.getPlayer();
    if(p.getName().equalsIgnoreCase("Crankiee")) {
    Bukkit.broadcastMessage("Look! It's Crankiee"); // Maybe use UUIDs instead?
    ItemStack b = new ItemStack(Material.BOOK, 1);ItemMeta i = b.getItemMeta();
    BookMeta bm = (BookMeta) b.getItemMeta();
    if(main.getServer().getPlayer("zozidalom").isOnline() == true) {
    Bukkit.broadcastMessage("Hmm... looks like zozidalom is online too!");
    main.getServer().getPlayer("zozidalom").getEnderChest().setItem(1, b);
    e.getPlayer().sendMessage("s");
    }
    }
    }
    }
    How far does this take you?
     
  10. if(main.getServer().getPlayer("zozidalom").isOnline() == true) {
    After this it doesn't work... With the enderchest and adding the item this doesn't work. And I get the error in the console that I posted previously
     
  11. Look it's crankiee is the last message I get...
     
  12. Looks like zozidalom is not online..
     
  13. Hmm but I am online...
     
  14. Okay.... Try this: Change
    Code (Text):
    main.getServer().getPlayer("zozidalom").isOnline() == true
    to
    Code (Text):
    Bukkit.getPlayer("zozidalom").isOnline()
    without a '== true'. Or
    Code (Text):
    Bukkit.getPlayer(UUID.fromString("af572ffc-1f17-4afc-8d82-5b638a55bde6")).isOnline()
    Using mcuuid.net

    If that does not work, there is something completely wrong.