Plugin doesn't make anything...

Discussion in 'Plugin Development' started by Dark-Panther, Apr 8, 2011.

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

    Dark-Panther

    Hey Guys,
    Sorry for posting, but I've a bad problem....
    There is no failure showed in eclipse, but the plugin doesn't work.
    Can you please take a look at at the source code?

    Console: It should give out: Works to here and a "Spruch"
    In game: FortuneCookie: + "Spruch"

    FortuneCookie.java
    Code:
    
    public class FortuneCookie extends JavaPlugin{
    
     private final Cookieevents cookieListener = new Cookieevents(this);
    
         public void onDisable() {
    
         System.out.println("FortuneCookie says bye bye!");
         }
    
         public void onEnable() {
         PluginManager pm = getServer().getPluginManager();
         pm.registerEvent(Event.Type.PLAYER_INTERACT , cookieListener, Priority.Normal, this);
    
         PluginDescriptionFile pdfFile = this.getDescription();
         System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
         }
    
    }
    
    Cookieevents

    Code:
    public class Cookieevents extends PlayerListener{
        static Random generator = new Random();
        public static FortuneCookie plugin;
        public Cookieevents(FortuneCookie instance){
            plugin = instance;
            }
    
        String[] Sprueche = {   "You will have a lot of fun!",
                "Beware of grief and hatred!",
                "The lucky is comming for you!",
                "Watch your steps!",
                "A bad workman always blames his tools.",
    
    // Gandhi, and other people said that,
    
                };
    
        public static String get (String[] array) {
            int rnd = Cookieevents.generator.nextInt(array.length);
           return array[rnd];
        }
    
        public void oncookieEating(PlayerInteractEvent event){
            if (event.getItem().getType()==Material.COOKIE) {
                if (event.getAction()==Action.RIGHT_CLICK_AIR) {
    
                    String ret = Cookieevents.get(Sprueche);
                    event.getPlayer().sendMessage(ChatColor.GREEN +"Fortune Cookie:"+ ret);
                    System.out.println("WORKS TO HERE!" + ret );
    
                }
                         }
            }
        }
     
  2. Offline

    ssell

    Doesn't this

    Code:
    public void oncookieEating( PlayerInteractEvent event ) ...
    
    need to be this?

    Code:
    @Override
    public void onPlayerInteract( PlayerInteractEvent event ) ...
    
     
  3. Offline

    Dark-Panther

    Mhh no? There is no supertype method to override....
    Another Idea?
     
  4. Offline

    ssell

    You are registered to receive the events, but you have no method to process when the event is sent out. This is why you need to change oncookieEating to onPlayerInteract
     
  5. Offline

    Carnes

    ssell is right. I just created a project from scratch to try it out. Change that line and you'll get random messages when you right click air with the correct selected item. I changed the item to a feather to test it out (i don't have any cookies).
     
  6. Offline

    Dark-Panther

    Wow, okay, thank you Guys...
    I'll note your names in the sourcecode, okay? :D
     
Thread Status:
Not open for further replies.

Share This Page