Working with PlayerChat and PlayerInteractEvent

Discussion in 'Plugin Development' started by Lutcikaur, Apr 26, 2011.

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

    Lutcikaur

    I am trying to make a simple plugin, where it accepts chat commands and detects for block manipulation.

    i have

    Code:
    public class PluginListener extends PlayerListener{
    ----
    ----
    ----
    for my PlayerChat commands to work, and i know that I need BlockListener for PlayerInteractEvent to work, and i know i need a new class for each of them, but I do not know how to bring variable data back and forth between the both of them, or how to set it up to listen for input from both of them. Any help is appreciated
     
  2. I'm not really sure what your asking but for transferring data between 2 classes you need to define the variable as public and static. Eg : public static int anynumber;

    You can then refer to that variable: private int myprivateint = ClassName.anynumber
     
  3. Offline

    Lutcikaur

    If i make a new class named Events and did this ::

    Code:
     package com.gmail.Lutcikaur.CTFPlugin;
    
    import org.bukkit.event.block.BlockListener;
    
    public class Events extends BlockListener{
    
    }
    
    would i be able to put a PlayerInteractEvent function inside and move variables from class PluginListener to class Event?
     
  4. Yeah, lets say you want to move mynumber from main class to block listener:

    Main Class
    Code:
    public static int mynumber = 10;
    Block Listener
    Code:
     package com.gmail.Lutcikaur.CTFPlugin;
    import org.bukkit.event.block.BlockListener;
    
    public class Events extends BlockListener{
    
        public static CTFPlugin plugin;
    
        public CTFPluginBlockListener(CTFPLugin instance) {
            plugin = instance;
        }
    
        onBlockBreak(BlockBreakEvent e){
            e.getPlayer().sendMessage("My int variable from main class : " + CTFPlugin.mynumber);
        }
    }
    
    See if that works.
     
Thread Status:
Not open for further replies.

Share This Page