(help) Issue with registering my events

Discussion in 'Plugin Development' started by joshcvb, Apr 29, 2012.

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

    joshcvb

    I'm having an issue registering my events in my program. If someone could offer some help that would be great. I thought I had all my packages called correctly and it keeps telling me about a wrong type in the console. Thanks.

    Code:
    package me.joshcvb.HardcoreAdventure;
     
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Set;
    import java.util.logging.Logger;
    import org.bukkit.Server;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.command.PluginCommand;
    import org.bukkit.configuration.Configuration;
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.FileConfigurationOptions;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.configuration.serialization.ConfigurationSerialization;
    import org.bukkit.event.Event;
    import org.bukkit.event.EventHandler;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.entity.Player;
     
    public class HardcoreAdventure extends JavaPlugin
    {
      private FileConfiguration hcConfig = null;
      private FileConfiguration hcPlayers = null;
      private FileConfiguration hcHighscores = null;
      private FileConfiguration hcPersonalBest = null;
      public Configuration config;
      private Logger _logger = Logger.getLogger("Minecraft");
      private String _pluginName;
      public HardcoreAdventure _thisPlugin;
      public static File directory;
     
      static
      {
        ConfigurationSerialization.registerClass(HCPlayer.class);
        ConfigurationSerialization.registerClass(HCAchievements.class);
      }
     
      public void onDisable()
      {
        PluginDescriptionFile yml = getDescription();
        saveHCPlayerFile();
        saveHCConfig();
        saveHCHighscoresFile();
        saveHCPersonalBestFile();
        this._logger.info(yml.getName() + " is now disabled.");
      }
     
      public void onEnable()
      {
        PluginDescriptionFile yml = getDescription();
        this._pluginName = yml.getName();
        log(yml.getVersion() + " loading.");
     
        directory = getDataFolder();
        this.hcConfig = getConfig();
        this.hcConfig.getDefaults();
        this.hcConfig.options().copyDefaults(true);
        saveConfig();
     
        File confFile = new File(getDataFolder(), "players.yml");
        this.hcPlayers = YamlConfiguration.loadConfiguration(confFile);
     
        if (!confFile.exists())
        {
          InputStream defConfigStream = getResource("players.yml");
          if (defConfigStream != null)
          {
            YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
            this.hcPlayers.setDefaults(defConfig);
          }
          saveHCPlayerFile();
        }
        else
        {
          ConfigurationSection cs = this.hcPlayers.getConfigurationSection("Players");
          if (cs == null)
          {
            this.hcPlayers.createSection("Players");
          }
          else
          {
            Set players = cs.getKeys(false);
     
            Object[] array = players.toArray();
     
            for (int i = 0; i < array.length; i++)
            {
              HCPlayer hcp = (HCPlayer)this.hcPlayers.get("Players." + array[i]);
     
              if ((hcp.getLives() == 0) || (hcp.getName().equals("")))
              {
                this.hcPlayers.set("Players." + array[i], null);
              }
              else
              {
                storePlayer(hcp);
              }
            }
          }
     
          saveHCPlayerFile();
        }
     
        HCAchievements ach = (HCAchievements)this.hcConfig.get("Achievements");
     
        if (ach == null)
        {
          ach = new HCAchievements();
          storeAchievements(ach);
          saveHCConfig();
        }
     
        File highscoreFile = new File(getDataFolder(), "highscores.yml");
        this.hcHighscores = YamlConfiguration.loadConfiguration(highscoreFile);
     
        if (!highscoreFile.exists())
        {
          InputStream defConfigStream = getResource("highscores.yml");
          if (defConfigStream != null)
          {
            YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
            this.hcHighscores.setDefaults(defConfig);
          }
          saveHCHighscoresFile();
        }
     
        File personalBestFile = new File(getDataFolder(), "personalbest.yml");
        this.hcPersonalBest = YamlConfiguration.loadConfiguration(personalBestFile);
     
        if (!personalBestFile.exists())
        {
          InputStream defConfigStream = getResource("personalbest.yml");
          if (defConfigStream != null)
          {
            YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
            this.hcPersonalBest.setDefaults(defConfig);
          }
          saveHCPersonalBestFile();
        }
        else
        {
          ConfigurationSection cs = this.hcPersonalBest.getConfigurationSection("Players");
          if (cs == null)
          {
            this.hcPersonalBest.createSection("Players");
          }
          else
          {
            Set players = cs.getKeys(false);
     
            Object[] array = players.toArray();
     
            for (int i = 0; i < array.length; i++)
            {
              HCPlayer hcp = (HCPlayer)this.hcPersonalBest.get("Players." + array[i]);
     
              storePersonalBest(hcp);
            }
          }
          saveHCPersonalBestFile();
        }
     
        PluginManager pm = getServer().getPluginManager();
        DeathEventListener deathListener = new DeathEventListener(this);
        RespawnEventListener spawnListener = new RespawnEventListener(this);
        PlayerEventListener playerListener = new PlayerEventListener(this);
        BlockEventsListeners blockListener = new BlockEventsListeners(this);
     
       
        pm.registerEvent(Event.Type.ENTITY_DEATH, deathListener, Event.Priority.Normal, this);
        pm.registerEvent(Event.Type.PLAYER_RESPAWN, spawnListener, Event.Priority.Normal, this);
        pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Event.Priority.Normal, this);
        pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
        pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Event.Priority.Normal, this);
        pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this);
     
        HardcoreAdventureCommandExecutor cmd = new HardcoreAdventureCommandExecutor(this);
        getCommand("hcadv").setExecutor(cmd);
     
        log(yml.getVersion() + " is now enabled!");
      }
     
      public void reloadConfigs()
      {
        saveHCConfig();
        saveHCPlayerFile();
        saveHCPersonalBestFile();
        loadPlayerFile();
        loadConfigFile();
        loadPersonalBestFile();
      }
     
      public void loadConfigFile()
      {
        this.hcConfig = getConfig();
      }
     
      public void loadPlayerFile()
      {
        File confFile = new File(getDataFolder(), "players.yml");
        this.hcPlayers = YamlConfiguration.loadConfiguration(confFile);
      }
     
      public void loadHighscoresFile()
      {
        File confFile = new File(getDataFolder(), "highscores.yml");
        this.hcHighscores = YamlConfiguration.loadConfiguration(confFile);
      }
     
      public void loadPersonalBestFile()
      {
        File confFile = new File(getDataFolder(), "personalbest.yml");
        this.hcPersonalBest = YamlConfiguration.loadConfiguration(confFile);
      }
     
      public FileConfiguration getPlayerFile()
      {
        return this.hcPlayers;
      }
     
      public FileConfiguration getHighscoresFile()
      {
        return this.hcHighscores;
      }
     
      public FileConfiguration getPersonalBestFile()
      {
        return this.hcPersonalBest;
      }
     
      public boolean saveHCPersonalBestFile()
      {
        try
        {
          this.hcPersonalBest.save(new File(getDataFolder(), "personalbest.yml"));
          return true;
        } catch (IOException e) {
          log("Could not save HardcoreAdventure personalbest.yml config.");
        }return false;
      }
     
      public boolean saveHCHighscoresFile()
      {
        try
        {
          this.hcHighscores.save(new File(getDataFolder(), "highscores.yml"));
          return true;
        } catch (IOException e) {
          log("Could not save HardcoreAdventure highscores.yml config.");
        }return false;
      }
     
      public boolean saveHCPlayerFile()
      {
        try
        {
          this.hcPlayers.save(new File(getDataFolder(), "players.yml"));
          return true;
        } catch (IOException e) {
          log("Could not save HardcoreAdventure players.yml config.");
        }return false;
      }
     
      public boolean saveHCConfig()
      {
        try
        {
          this.hcConfig.save(new File(getDataFolder(), "config.yml"));
          return true;
        } catch (IOException e) {
          log("Could not save HardcoreAdventure config.yml config.");
        }return false;
      }
     
      public void storePersonalBest(HCPlayer player)
      {
        getPersonalBestFile().set("Players." + player.getName(), player);
      }
     
      public void storePlayer(HCPlayer player)
      {
        getPlayerFile().set("Players." + player.getName(), player);
      }
     
      public void storeAchievements(HCAchievements ach)
      {
        this.hcConfig.set("Achievements", ach);
      }
     
      public void log(String message) {
        this._logger.info("[" + this._pluginName + "] " + message);
      }
    }
    
     
  2. Offline

    coldandtired

    That's the old way of events.

    The new way is to implement Listener in a class, add all your event handlers to it, then register all the events in one go.
     
Thread Status:
Not open for further replies.

Share This Page