[UNSOLVED] Getting config int not working! HELP

Discussion in 'Plugin Development' started by Xeno_1, Nov 7, 2013.

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

    Xeno_1

    Im Trying to get a int but it's not working

    Code:
    package me.xeno.herocraft.config;
     
     
    import me.xeno.herocraft.HeroCraft;
     
    public class blo {
        static HeroCraft plugin;
        public blo(HeroCraft plugin) {
            this.plugin = plugin;
        }
        private static int irontimer = plugin.getConfig().getInt("Classes.IronMan.BootsTimer");
        private static int cooldowntime = plugin.getConfig().getInt("Classes.IronMan.BootsCooldown");
       
        public static int getCooldownTimer() {
            return cooldowntime;
        }
        public static int getIronTimer() {
            return irontimer;
        }
       
    }
    


    plugin.yml
    Code:
    #HeroCraft Configuration
     
    # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
     
    # World settings.
     
    Multiworld: # If you can't figure out why Hero isn't running on your server, ensure your main world is in the list of enabled worlds.
      ENABLED:
        - world
    Classes:
      IronMan:
        BootsCooldown: 30
        BootsTime: 30    

    Crash
    Code:
    Saving: true
    2013-11-07 20:02:05 [INFO] Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    2013-11-07 20:02:05 [INFO] [HeroCraft] Disabling HeroCraft v0.1
    2013-11-07 20:02:05 [INFO] [HeroCraft] HeroCraftVersion 0.1 has been disabled!
    2013-11-07 20:02:05 [INFO] [HeroCraft] Loading HeroCraft v0.1
    2013-11-07 20:02:05 [INFO] [HeroCraft] Enabling HeroCraft v0.1
    2013-11-07 20:02:05 [SEVERE] Error occurred while enabling HeroCraft v0.1 (Is it up to date?)
    java.lang.ExceptionInInitializerError
        at me.xeno.herocraft.HeroCraft.onEnable(HeroCraft.java:28)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:382)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(CraftServer.java:288)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(CraftServer.java:270)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.reload(CraftServer.java:618)
        at org.bukkit.Bukkit.reload(Bukkit.java:277)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:24)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:532)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchServerCommand(CraftServer.java:519)
        at net.minecraft.server.v1_6_R3.DedicatedServer.as(DedicatedServer.java:276)
        at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:241)
        at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:493)
        at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:425)
        at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.NullPointerException
        at me.xeno.herocraft.config.blo.<clinit>(blo.java:11)
        ... 17 more
    2013-11-07 20:02:05 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2013-11-07 20:02:05 [INFO] CONSOLE: Reload complete.
    2013-11-07 20:11:24 [INFO] -------- World Settings For [world] --------
    2013-11-07 20:11:24 [INFO] View Distance: 10
    2013-11-07 20:11:24 [INFO] Chunks to Grow per Tick: 650
    2013-11-07 20:11:24 [INFO] Experience Merge Radius: 3.0
    2013-11-07 20:11:24 [INFO] Item Despawn Rate: 6000
    2013-11-07 20:11:24 [INFO] Item Merge Radius: 2.5
    2013-11-07 20:11:24 [INFO] Arrow Despawn Rate: 1200
    2013-11-07 20:11:24 [INFO] Cactus Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Cane Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Melon Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Mushroom Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Pumpkin Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Sapling Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Wheat Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Entity Activation Range: An 32 / Mo 32 / Mi 16
    2013-11-07 20:11:24 [INFO] Anti X-Ray: true
    2013-11-07 20:11:24 [INFO]    Engine Mode: 1
    2013-11-07 20:11:24 [INFO]    Blocks: [1, 5, 14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    2013-11-07 20:11:24 [INFO] Mob Spawn Range: 4
    2013-11-07 20:11:24 [INFO] Random Lighting Updates: false
    2013-11-07 20:11:24 [INFO] Hopper Transfer: 8 Hopper Check: 8
    2013-11-07 20:11:24 [INFO] Structure Info Saving: true
    2013-11-07 20:11:24 [INFO] Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    2013-11-07 20:11:24 [INFO] -------- World Settings For [world_nether] --------
    2013-11-07 20:11:24 [INFO] View Distance: 10
    2013-11-07 20:11:24 [INFO] Chunks to Grow per Tick: 650
    2013-11-07 20:11:24 [INFO] Experience Merge Radius: 3.0
    2013-11-07 20:11:24 [INFO] Item Despawn Rate: 6000
    2013-11-07 20:11:24 [INFO] Item Merge Radius: 2.5
    2013-11-07 20:11:24 [INFO] Arrow Despawn Rate: 1200
    2013-11-07 20:11:24 [INFO] Cactus Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Cane Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Melon Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Mushroom Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Pumpkin Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Sapling Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Wheat Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Entity Activation Range: An 32 / Mo 32 / Mi 16
    2013-11-07 20:11:24 [INFO] Anti X-Ray: true
    2013-11-07 20:11:24 [INFO]    Engine Mode: 1
    2013-11-07 20:11:24 [INFO]    Blocks: [1, 5, 14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    2013-11-07 20:11:24 [INFO] Mob Spawn Range: 4
    2013-11-07 20:11:24 [INFO] Random Lighting Updates: false
    2013-11-07 20:11:24 [INFO] Hopper Transfer: 8 Hopper Check: 8
    2013-11-07 20:11:24 [INFO] Structure Info Saving: true
    2013-11-07 20:11:24 [INFO] Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    2013-11-07 20:11:24 [INFO] -------- World Settings For [world_the_end] --------
    2013-11-07 20:11:24 [INFO] View Distance: 10
    2013-11-07 20:11:24 [INFO] Chunks to Grow per Tick: 650
    2013-11-07 20:11:24 [INFO] Experience Merge Radius: 3.0
    2013-11-07 20:11:24 [INFO] Item Despawn Rate: 6000
    2013-11-07 20:11:24 [INFO] Item Merge Radius: 2.5
    2013-11-07 20:11:24 [INFO] Arrow Despawn Rate: 1200
    2013-11-07 20:11:24 [INFO] Cactus Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Cane Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Melon Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Mushroom Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Pumpkin Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Sapling Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Wheat Growth Modifier: 100%
    2013-11-07 20:11:24 [INFO] Entity Activation Range: An 32 / Mo 32 / Mi 16
    2013-11-07 20:11:24 [INFO] Anti X-Ray: true
    2013-11-07 20:11:24 [INFO]    Engine Mode: 1
    2013-11-07 20:11:24 [INFO]    Blocks: [1, 5, 14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    2013-11-07 20:11:24 [INFO] Mob Spawn Range: 4
    2013-11-07 20:11:24 [INFO] Random Lighting Updates: false
    2013-11-07 20:11:24 [INFO] Hopper Transfer: 8 Hopper Check: 8
    2013-11-07 20:11:24 [INFO] Structure Info Saving: true
    2013-11-07 20:11:24 [INFO] Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    2013-11-07 20:11:24 [INFO] [HeroCraft] Disabling HeroCraft v0.1
    2013-11-07 20:11:24 [INFO] [HeroCraft] HeroCraftVersion 0.1 has been disabled!
    2013-11-07 20:11:24 [INFO] [HeroCraft] Loading HeroCraft v0.1
    2013-11-07 20:11:24 [INFO] [HeroCraft] Enabling HeroCraft v0.1
    2013-11-07 20:11:24 [SEVERE] Error occurred while enabling HeroCraft v0.1 (Is it up to date?)
    java.lang.ExceptionInInitializerError
        at me.xeno.herocraft.HeroCraft.onEnable(HeroCraft.java:28)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:382)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(CraftServer.java:288)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(CraftServer.java:270)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.reload(CraftServer.java:618)
        at org.bukkit.Bukkit.reload(Bukkit.java:277)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:24)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:532)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchServerCommand(CraftServer.java:519)
        at net.minecraft.server.v1_6_R3.DedicatedServer.as(DedicatedServer.java:276)
        at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:241)
        at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:493)
        at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:425)
        at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.NullPointerException
        at me.xeno.herocraft.config.blo.<clinit>(blo.java:11)
        ... 17 more
     
  2. I think you posted your config.yml when you said you posted your plugin.yml

    Inside your main class, create a instance of your class inside the onEnable(), instead as instance variable

    The config is null inside javaplugin before the onEnable() is called

    Notice: the config is actually created before onEnable(), even before onLoad(), but we say its created before onEnable() for simplicity reasons
     
  3. Offline

    drtshock

    You can't call getConfig() outside of a method.

    Also, the key you are calling from your class is different than the one in your actual config file :\
     
  4. Offline

    Xeno_1

    Yea but this worked for my other plugin
     
  5. Offline

    1Rogue


    Probably because it was in a method.
     
    Xeno_1 likes this.
  6. Offline

    Xeno_1

    So i should use it in a method
     
  7. Offline

    1Rogue


    Yes. Yes you should
     
  8. Offline

    Xeno_1

    Ok i did but it still not working, Only works for the timer

    Main
    Code:
    package me.xeno.herocraft;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import me.xeno.herocraft.config.DataManager;
    import me.xeno.herocraft.config.blo;
    import me.xeno.herocraft.events.IronBoots;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class HeroCraft extends JavaPlugin {
        public static List<String> worlds = new ArrayList<String>();
        public String[] array = worlds.toArray(new String[0]);
       
        DataManager dm = DataManager.getInstance();
        public static String PREFIX = ChatColor.RED + "[" + ChatColor.AQUA
                + "HeroBattles" + ChatColor.RED + "] " + ChatColor.GRAY;
     
     
        public void onEnable() {
            new IronBoots(this);
            new blo(this);
            this.dm.setupData(this);
            load(this.getConfig());
            this.getConfig().options().copyDefaults(true);
            this.saveDefaultConfig();
            new blo(this);
            PluginDescriptionFile pd = this.getDescription();
            getLogger().info(
                    pd.getName() + "Version " + pd.getVersion()
                            + " has been enabled!");
            for (String s : array) {
                try {
                    getLogger().info(
                            pd.getName() + "Version " + pd.getVersion() + " " + s
                                    + " HAS BEEN SET TO A HEROWORLD!");
                    Bukkit.getWorld(s);
                    worlds.add(s);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
     
        public void onDisable() {
            PluginDescriptionFile pd = this.getDescription();
            getLogger().info(
                    pd.getName() + "Version " + pd.getVersion()
                            + " has been disabled!");
        }
       
       
        private void load(FileConfiguration file){
              blo.cooldowntime = file.getInt("Classes.IronMan.BootsCooldown");
              blo.irontimer =  file.getInt("Classes.IronMan.BootsTimer");
        }
     
    }
    
    BLO
    Code:
    package me.xeno.herocraft.config;
     
     
    import me.xeno.herocraft.HeroCraft;
     
    public class blo {
        static HeroCraft plugin;
        public blo(HeroCraft plugin) {
            this.plugin = plugin;
        }
        public static int irontimer;
        public static int cooldowntime;
       
        public static int getCooldownTimer() {
            return cooldowntime;
        }
        public static int getIronTimer() {
            return irontimer;
        }
       
    }
    
    EVENT CLASS
    Code:
    package me.xeno.herocraft.events;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
     
    import me.xeno.herocraft.HeroCraft;
    import me.xeno.herocraft.config.DataManager;
    import me.xeno.herocraft.config.blo;
     
    public class IronBoots implements Listener {
        HeroCraft plugin;
        public static int id;
        public List<Player> flyers = new ArrayList<Player>();
        public List<Player> cooldownt = new ArrayList<Player>();
        public List<Player> fallers = new ArrayList<Player>();
        List<String> worlds = HeroCraft.worlds;
        DataManager dm = DataManager.getInstance();
     
        public IronBoots(HeroCraft plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
            this.plugin = plugin;
        }
     
        @EventHandler
        public void onMove(PlayerMoveEvent event) {
            if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
                    if (event.getPlayer().getLocation().getBlock()
                            .getRelative(BlockFace.DOWN).getType() == Material.AIR && event.getPlayer().getInventory().getBoots().getType() == Material.IRON_BOOTS) {
                        if (!flyers.contains(event.getPlayer())) {
                            if (!cooldownt.contains(event.getPlayer())) {
                                event.getPlayer()
                                        .sendMessage(
                                                ChatColor
                                                        .translateAlternateColorCodes(
                                                                '&',
                                                                HeroCraft.PREFIX
                                                                        + "&bYOU HAVE ENABLED YOU IRON-MAN BOOTS!"));
                                flyers.add(event.getPlayer());
                                startTimer(event.getPlayer());
                                event.getPlayer().setAllowFlight(true);
                                event.getPlayer().setFlying(true);
                                event.getPlayer()
                                        .getWorld()
                                        .playSound(event.getPlayer().getLocation(),
                                                Sound.FIZZ, 1.0F, 5.0F);
                                effectCheck(event.getPlayer());
                            }
                        }
                    }
                }
        }
     
        private void startTimer(final Player player) {
            id = Bukkit.getServer().getScheduler()
                    .scheduleSyncDelayedTask(plugin, new Runnable() {
                        public void run() {
                            if (flyers.contains(player)) {
                                player.sendMessage(ChatColor
                                        .translateAlternateColorCodes(
                                                '&',
                                                HeroCraft.PREFIX
                                                        + "&bIRON BOOTS HAS OVERHEATED, WAIT FOR COOLDOWN"));
                                player.setAllowFlight(false);
                                player.getPlayer().setFlying(false);
                                flyers.remove(player);
                                cooldownt.add(player);
                                cool(player);
                                fallers.add(player);
                            }
                        }
                    }, blo.getIronTimer() * 20);
           
        }
     
        private void cool(final Player player) {
            id = Bukkit.getServer().getScheduler()
                    .scheduleSyncDelayedTask(plugin, new Runnable() {
                        public void run() {
                            if (cooldownt.contains(player)) {
                                player.sendMessage(ChatColor
                                        .translateAlternateColorCodes(
                                                '&',
                                                HeroCraft.PREFIX
                                                        + "&bJET BOOTS HAS COOLED DOWN!"));
                                cooldownt.remove(player);
                            }
                        }
                    }, blo.getCooldownTimer() * 20);// It wont't read this
        }
     
        @EventHandler
        public void onPlayerDamage(EntityDamageEvent e) {
            if ((e.getEntity() instanceof Player)) {
                Player p = (Player) e.getEntity();
                if ((e.getCause() == EntityDamageEvent.DamageCause.FALL)
                        && (fallers.contains(p))) {
                    e.setDamage(0.0D);
                    fallers.remove(p);
                }
            }
        }
     
        @SuppressWarnings("unused")
        private void stopScheduler() {
            Bukkit.getServer().getScheduler().cancelTask(id);
        }
     
        private void effectCheck(final Player player) {
            Bukkit.getServer().getScheduler()
                    .scheduleSyncRepeatingTask(plugin, new Runnable() {
                        public void run() {
                            if (flyers.contains(player)) {
                                try {
                                    ParticleEffects.FLAME.sendToPlayer(player,
                                            player.getLocation(), 1.0F, 1.0F, 1.0F,
                                            1.0F, 30);
                                    ParticleEffects.LARGE_SMOKE.sendToPlayer(player,
                                            player.getLocation(), 1.0F, 1.0F, 1.0F,
                                            1.0F, 200);
                                    player
                                    .getWorld()
                                    .playSound(player.getLocation(),
                                            Sound.FIZZ, 1.0F, 5.0F);
                                    player.setExp(0.0F);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
     
                    }, 10, 10);
     
        }
    }
    
     
  9. Offline

    1Rogue

    Don't pass "getConfig()", just call the method itself. You can use "this.getConfig()" within the method since it is still in the main class.
     
  10. Offline

    Xeno_1

    Still doesn't work. D:
    Code:
    package me.xeno.herocraft;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import me.xeno.herocraft.config.DataManager;
    import me.xeno.herocraft.config.blo;
    import me.xeno.herocraft.events.IronBoots;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class HeroCraft extends JavaPlugin {
        public static List<String> worlds = new ArrayList<String>();
        public String[] array = worlds.toArray(new String[0]);
        public static List<String> addedworlds = new ArrayList<String>();
        public String[] addedarray = worlds.toArray(new String[0]);
        public boolean sucess = false;
        public boolean getSucess(){return sucess;}
        DataManager dm = DataManager.getInstance();
        public static String PREFIX = ChatColor.RED + "[" + ChatColor.AQUA
                + "HeroBattles" + ChatColor.RED + "] " + ChatColor.GRAY;
     
     
        public void onEnable() {
            new IronBoots(this);
            new blo(this);
            this.dm.setupData(this);
            load();
            this.getConfig().options().copyDefaults(true);
            this.saveDefaultConfig();
            new blo(this);
            PluginDescriptionFile pd = this.getDescription();
            getLogger().info(
                    pd.getName() + "Version " + pd.getVersion()
                            + " has been enabled!");
            for (String s : array) {
                try {
     
                    Bukkit.getWorld(s);
                    worlds.add(s);
                    addedworlds.add(s);
                    sucess = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
           
            if(getSucess()){
                for (String s : addedworlds){
                    getLogger().info(
                            pd.getName() + "Version " + pd.getVersion() + " " + s
                                    + " HAS BEEN SET TO A HEROWORLD!");
                }
            }
        }
     
        public void onDisable() {
            PluginDescriptionFile pd = this.getDescription();
            getLogger().info(
                    pd.getName() + "Version " + pd.getVersion()
                            + " has been disabled!");
        }
       
       
        private void load(){
              blo.irontimer =  this.getConfig().getInt("Classes.IronMan.BootsTimer");
              blo.cooldowntime = this.getConfig().getInt("Classes.IronMan.BootsCooldown");
         
        }
     
    }
    
    Still need help
     
  11. Offline

    drtshock

    Xeno_1 likes this.
  12. Offline

    Xeno_1

  13. Offline

    drtshock

  14. Offline

    Xeno_1

    I know what I am doing it's just that I cannot get a int value from my config file.
     
  15. Offline

    drtshock

  16. Offline

    Xeno_1

  17. Offline

    drtshock

    Yes but why are you creating a new instance of a static class for objects that are already saved in memory? That's just using more ram than you should be using.
     
  18. Offline

    Xeno_1

    Because the other way i had it was not working either.
    Here I'll try again




    Didn't work once again!

    MAIN
    Code:java
    1. package me.xeno.herocraft;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import me.xeno.herocraft.config.DataManager;
    7. import me.xeno.herocraft.config.blo;
    8. import me.xeno.herocraft.events.IronBoots;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class HeroCraft extends JavaPlugin {
    16. public static List<String> worlds = new ArrayList<String>();
    17. public String[] array = worlds.toArray(new String[0]);
    18. public static List<String> addedworlds = new ArrayList<String>();
    19. public String[] addedarray = worlds.toArray(new String[0]);
    20. public boolean sucess = false;
    21. public boolean getSucess(){return sucess;}
    22. DataManager dm = DataManager.getInstance();
    23. public static String PREFIX = ChatColor.RED + "[" + ChatColor.AQUA
    24. + "HeroBattles" + ChatColor.RED + "] " + ChatColor.GRAY;
    25. private int irontimer;
    26. private int cooldowntime;
    27.  
    28. public void onEnable() {
    29. new IronBoots(this, getCooldownTimer(), getIronTimer() );
    30. this.dm.setupData(this);
    31. load();
    32. this.getConfig().options().copyDefaults(true);
    33. this.saveDefaultConfig();
    34. new blo(this);
    35. PluginDescriptionFile pd = this.getDescription();
    36. getLogger().info(
    37. pd.getName() + "Version " + pd.getVersion()
    38. + " has been enabled!");
    39. for (String s : array) {
    40. try {
    41.  
    42. Bukkit.getWorld(s);
    43. worlds.add(s);
    44. addedworlds.add(s);
    45. sucess = true;
    46. } catch (Exception e) {
    47. e.printStackTrace();
    48. }
    49. }
    50.  
    51. if(getSucess()){
    52. for (String s : addedworlds){
    53. getLogger().info(
    54. pd.getName() + "Version " + pd.getVersion() + " " + s
    55. + " HAS BEEN SET TO A HEROWORLD!");
    56. }
    57. }
    58. }
    59.  
    60. public void onDisable() {
    61. PluginDescriptionFile pd = this.getDescription();
    62. getLogger().info(
    63. pd.getName() + "Version " + pd.getVersion()
    64. + " has been disabled!");
    65. }
    66.  
    67. public int getInt(String path) {
    68. return 0;
    69. }
    70. private void load(){
    71. blo.irontimer = this.getConfig().getInt("Classes.IronMan.BootsTimer");
    72. blo.cooldowntime = this.getConfig().getInt("Classes.IronMan.BootsCooldown");
    73.  
    74. }
    75.  
    76. public int getCooldownTimer() {
    77. return this.cooldowntime;
    78. }
    79. public int getIronTimer() {
    80. return this.irontimer;
    81. }
    82.  
    83.  
    84. }
    85.  




    EVENT
    Code:java
    1. package me.xeno.herocraft.events;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.GameMode;
    9. import org.bukkit.Material;
    10. import org.bukkit.Sound;
    11. import org.bukkit.block.Block;
    12. import org.bukkit.block.BlockFace;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.entity.EntityDamageEvent;
    17. import org.bukkit.event.player.PlayerMoveEvent;
    18.  
    19. import me.xeno.herocraft.HeroCraft;
    20. import me.xeno.herocraft.config.DataManager;
    21. import me.xeno.herocraft.config.blo;
    22.  
    23. public class IronBoots implements Listener {
    24. HeroCraft plugin;
    25. public static int id;
    26. public List<Player> flyers = new ArrayList<Player>();
    27. public List<Player> cooldownt = new ArrayList<Player>();
    28. public List<Player> fallers = new ArrayList<Player>();
    29. private int cooldown;
    30. private int timer;
    31. List<String> worlds = HeroCraft.worlds;
    32. DataManager dm = DataManager.getInstance();
    33.  
    34. public IronBoots(HeroCraft plugin, int cooldown, int timer) {
    35. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    36. this.plugin = plugin;
    37. this.timer = timer;
    38. this.cooldown = cooldown;
    39. }
    40.  
    41. @EventHandler
    42. public void onMove(PlayerMoveEvent event) {
    43. if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
    44. if (event.getPlayer().getLocation().getBlock()
    45. .getRelative(BlockFace.DOWN).getType() == Material.AIR && event.getPlayer().getInventory().getBoots().getType() == Material.IRON_BOOTS) {
    46. if (!flyers.contains(event.getPlayer())) {
    47. if (!cooldownt.contains(event.getPlayer())) {
    48. event.getPlayer()
    49. .sendMessage(
    50. ChatColor
    51. .translateAlternateColorCodes(
    52. '&',
    53. HeroCraft.PREFIX
    54. + "&bYOU HAVE ENABLED YOU IRON-MAN BOOTS!"));
    55. flyers.add(event.getPlayer());
    56. startTimer(event.getPlayer());
    57. event.getPlayer().setAllowFlight(true);
    58. event.getPlayer().setFlying(true);
    59. event.getPlayer()
    60. .getWorld()
    61. .playSound(event.getPlayer().getLocation(),
    62. Sound.FIZZ, 1.0F, 5.0F);
    63. effectCheck(event.getPlayer());
    64. }
    65. }
    66. }
    67. }
    68. }
    69.  
    70. private void startTimer(final Player player) {
    71. id = Bukkit.getServer().getScheduler()
    72. .scheduleSyncDelayedTask(plugin, new Runnable() {
    73. public void run() {
    74. if (flyers.contains(player)) {
    75. player.sendMessage(ChatColor
    76. .translateAlternateColorCodes(
    77. '&',
    78. HeroCraft.PREFIX
    79. + "&bIRON BOOTS HAS OVERHEATED, WAIT FOR COOLDOWN"));
    80. player.setAllowFlight(false);
    81. player.getPlayer().setFlying(false);
    82. flyers.remove(player);
    83. cooldownt.add(player);
    84. cool(player);
    85. fallers.add(player);
    86. }
    87. }
    88. }, timer * 20);
    89.  
    90. }
    91.  
    92. private void cool(final Player player) {
    93. id = Bukkit.getServer().getScheduler()
    94. .scheduleSyncDelayedTask(plugin, new Runnable() {
    95. public void run() {
    96. if (cooldownt.contains(player)) {
    97. player.sendMessage(ChatColor
    98. .translateAlternateColorCodes(
    99. '&',
    100. HeroCraft.PREFIX
    101. + "&bJET BOOTS HAS COOLED DOWN!"));
    102. cooldownt.remove(player);
    103. }
    104. }
    105. }, cooldown * 20);// It wont't read this
    106. }
    107.  
    108. @EventHandler
    109. public void onPlayerDamage(EntityDamageEvent e) {
    110. if ((e.getEntity() instanceof Player)) {
    111. Player p = (Player) e.getEntity();
    112. if ((e.getCause() == EntityDamageEvent.DamageCause.FALL)
    113. && (fallers.contains(p))) {
    114. e.setDamage(0.0D);
    115. fallers.remove(p);
    116. }
    117. }
    118. }
    119.  
    120. @SuppressWarnings("unused")
    121. private void stopScheduler() {
    122. Bukkit.getServer().getScheduler().cancelTask(id);
    123. }
    124.  
    125. private void effectCheck(final Player player) {
    126. Bukkit.getServer().getScheduler()
    127. .scheduleSyncRepeatingTask(plugin, new Runnable() {
    128. public void run() {
    129. if (flyers.contains(player)) {
    130. try {
    131. ParticleEffects.FLAME.sendToPlayer(player,
    132. player.getLocation(), 1.0F, 1.0F, 1.0F,
    133. 1.0F, 30);
    134. ParticleEffects.LARGE_SMOKE.sendToPlayer(player,
    135. player.getLocation(), 1.0F, 1.0F, 1.0F,
    136. 1.0F, 200);
    137. player
    138. .getWorld()
    139. .playSound(player.getLocation(),
    140. Sound.FIZZ, 1.0F, 5.0F);
    141. player.setExp(0.0F);
    142. } catch (Exception e) {
    143. e.printStackTrace();
    144. }
    145. }
    146. }
    147.  
    148. }, 10, 10);
    149.  
    150. }
    151. }
    152.  
     
  19. Offline

    drtshock

    Why do you have static objects in your class? Why are you still saving config values in static objects when you can just access the config from the plugin instance which is saved in memory?
     
  20. Offline

    Xeno_1


    I have no idea. I really didn't write well because of this issue.



    I didn't use static objects for getting the integer config value.

    Once again this is becoming impossible

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  21. Offline

    McMhz

    You just blew my mind.
     
  22. Offline

    Xeno_1

    Huh?
     
  23. Offline

    McMhz

    What is it that you need? The int returns 0 or what..

    Xeno_1
    btw what's on line 28 on HeroCraft class.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  24. Offline

    Xeno_1


    That was a test


    And what are you talking about in 28?
     
  25. Offline

    McMhz

    Xeno_1
    Sorry, I wrote Line wrong
     
  26. Offline

    Xeno_1

    You think you know the problem?
     
  27. Offline

    apple2114

    im having the same issue with this
    Code:java
    1. int Size = getConfig().getInt("Inventory");
     
  28. Offline

    apple2114

    To the problem all you have to do is this when setting an int in a config you must set it like so...
    Code:java
    1. getConfig().set("PLACE IN CONFIG", 92013);
    do NOT use quotes that will make it think it is a string instead of a int. So I believe you can set this as Solved now.
     
  29. Offline

    d3v1n302418

    Sorry for being late, but your are using the "new blo(this);" before using the load() void. That will cause an NPE on the onEnabe().
     
Thread Status:
Not open for further replies.

Share This Page