Solved Listeners? Where are you?

Discussion in 'Plugin Development' started by MieskeB, Oct 19, 2017.

Thread Status:
Not open for further replies.
  1. My Listeners aren't working properly, at least they don't have any signs of life in them... (yes I am back again with a question, sorry)

    UHC.java:
    Code:
    package com.themlgkillerpro.main;
    
    import java.io.File;
    import java.util.Arrays;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.themlgkillerpro.main.handlers.Kit;
    import com.themlgkillerpro.main.listener.MGListener;
    import com.themlgkillerpro.main.listener.player.AsyncPlayerPreLogin;
    import com.themlgkillerpro.main.listener.player.PlayerDeath;
    import com.themlgkillerpro.main.listener.player.PlayerJoin;
    import com.themlgkillerpro.main.listener.player.PlayerQuit;
    import com.themlgkillerpro.main.threads.StartCountdown;
    
    public class UHC extends JavaPlugin {
    
        //TODO IMPORTANT LIST
        //TODO add teams to config file
        //TODO add maps to config file
        //TODO (map voting (like kits), map reset, respawning gm3 ipv kick)
       
       
        public static int startCountdownId;
    
        public void onEnable() {
    
            GameState.setState(GameState.IN_LOBBY);
    
            setupConfig();
            registerKits();
    
            startCountdown();
        }
    
        public void registerListeners() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new MGListener(this), this);
        }
    
        public void setupConfig() {
            File resetFile = new File(getDataFolder(), "RESET.FILE");
           
            if (resetFile.exists())
                return;
           
            FileConfiguration config = getConfig();
            config.set("Kits.Basic.Items", Arrays.asList("272", "297:5"));
            config.set("Kits.Basic.Display Item", 272);
            config.set("Kits.Warrior.Items", Arrays.asList("272", "297:5"));
            config.set("Kits.Warrior.Display Item", 272);
            saveConfig();
            try {
                resetFile.createNewFile();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public void registerKits() {
            FileConfiguration config = getConfig();
            for (String s : getConfig().getConfigurationSection("Kits").getKeys(false)) {
                String path = "Kits." + s + ".";
                new Kit(s, config.getStringList(path + "Items"), config.getInt(path + "Display Item"));
            }
        }
    
        @SuppressWarnings("deprecation")
        public void startCountdown() {
            StartCountdown.timeUntilStart = 60;
            startCountdownId = getServer().getScheduler().scheduleSyncRepeatingTask(this, new StartCountdown(this), 20, 20);
        }
    
        public void stopCountdown() {
            getServer().getScheduler().cancelTask(startCountdownId);
        }
    
        public void restartCountdown() {
            stopCountdown();
            startCountdown();
        }
    }
    
    MGListener.java:
    Code:
    package com.themlgkillerpro.main.listener;
    
    import org.bukkit.event.Listener;
    
    import com.themlgkillerpro.main.UHC;
    
    public class MGListener implements Listener{
       
        UHC plugin;
       
        public MGListener(UHC pl) {
            plugin = pl;
        }
       
    }
    
    PlayerJoin.java:
    Code:
    package com.themlgkillerpro.main.listener.player;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import com.themlgkillerpro.main.UHC;
    import com.themlgkillerpro.main.handlers.Game;
    import com.themlgkillerpro.main.listener.MGListener;
    import com.themlgkillerpro.main.utils.InventoryUtilities;
    import com.themlgkillerpro.main.utils.LocationUtilities;
    
    public class PlayerJoin extends MGListener{
    
        public PlayerJoin(UHC pl) {
            super(pl);
        }
       
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
                   
            Game.setCanStart(Bukkit.getOnlinePlayers().size() >= 2 );
           
            LocationUtilities.teleportToSpawn(player);
            InventoryUtilities.clearInventory(player);
           
            ItemStack is = new ItemStack(Material.DIAMOND_SWORD);
            ItemMeta im = is.getItemMeta();
            im.setDisplayName(ChatColor.GREEN + "Kits");
            is.setItemMeta(im);
            player.getInventory().addItem(is);
            player.updateInventory();
        }
    }
    
    I think it has something to do with the extends MGListener but I can not find what to do with it...
     
  2. Offline

    timtower Administrator Administrator Moderator

    @MieskeB And where do you call registerListeners() ?
     
  3. Offline

    MightyOne

    And he deleted it xD whatever. I just wanted to add that in my eyes it is a very common mistake to not register Listeners. I have already been very confused many times when nothing happened ingame but thankfully we have this forum to ask other people for help.
     
Thread Status:
Not open for further replies.

Share This Page