[URGENT_HELP] PLUGIN RELOAD!

Discussion in 'Plugin Development' started by creepers84, Jun 17, 2013.

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

    creepers84

    I have the following code:
    Code:
    package me.creepers84.projectileheads;
     
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.WitherSkull;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.BlockIgniteEvent;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.entity.EntityExplodeEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.util.Vector;
    public class ProjectileHeads extends JavaPlugin implements Listener {
    public final Logger logger = Logger.getLogger("Minecraft");
    public static ProjectileHeads plugin;
     
    public File config;
    public FileConfiguration pConfig;
     
    @Override
    public void onEnable() {
        setupTimer();
        if(!(new File("plugins/ProjectileHeads/config.yml")).exists()){
            saveResource("config.yml", false);
    this.logger.info("[ProjectileHeads] Plugin Enabled");
    getServer().getPluginManager().registerEvents(this, this);
    getConfig().options().copyDefaults(true);
    saveDefaultConfig();
        }
    }
     
    @EventHandler
    public void PlayerJoinEvent(PlayerJoinEvent e){
        setScoreboard(e.getPlayer());
        config = new File("plugins/ProjectileHeads/config.yml");
        pConfig = YamlConfiguration.loadConfiguration(config);
        if(!config.exists()){
            pConfig.set(e.getPlayer().getName() + ".kills", "0");
            pConfig.set(e.getPlayer().getName() + ".deaths", "0");
            try {
                pConfig.save(config);
            } catch (IOException ex){ex.printStackTrace();}
        }
    }
     
    @EventHandler
    public void PlayerDeathEvent(PlayerDeathEvent e){
        Player p = e.getEntity().getPlayer();
     
        if (p.getKiller() instanceof Player){
            Player k = p.getKiller();
     
            setDeaths(p, getDeaths(p.getName()) + 1);
            setKills(k, getKills(k.getName()) + 1);
     
            setScoreboard(p);
            setScoreboard(k);
        } else {
            Player k = p.getKiller();
            getConfig().set(p.getName() + ".deaths", getDeaths(p.getName()) + 1);
            getConfig().set(k.getName() + ".kills", getKills(k.getName()) + 1);
            saveConfig();
     
            setScoreboard(p);
        }
    }
     
    public void setScoreboard(Player p){
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        Scoreboard board = manager.getNewScoreboard();
     
            Objective objective = board.registerNewObjective("test", "dummy");
     
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(" §b§lProjectileHeads");
     
            Score kills = objective.getScore(Bukkit.getOfflinePlayer("§aKills§7:§c"));
            kills.setScore(getKills(p.getName()));
     
            Score deaths = objective.getScore(Bukkit.getOfflinePlayer("§aDeaths§7:§c"));
            deaths.setScore(getDeaths(p.getName()));
     
            p.setScoreboard(board);
     
    }
     
    public int getKills(String p)
    {
        if(getConfig().get(p + ".kills") != null){
            return getConfig().getInt(p + ".kills");
        } else {
            return 0;
        }
    }
     
    public int getDeaths(String p)
    {
        return getConfig().getInt(p + ".deaths");
    }
     
    public double getKDR(Player p)
    {
        return getConfig().getDouble(p.getName() + ".kills") / getConfig().getDouble(p.getName() + ".deaths");
     
    }
    public void setKills(Player p, int Kills)
    {
        getConfig().set(p.getName() + ".kills", Kills);
        saveConfig();
    }
     
    public void setDeaths(Player p, int Deaths)
    {
        getConfig().set(p.getName() + ".deaths", Deaths);
        saveConfig();
    }
     
    public void setupTimer()
    {
        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
        {
            public void run() {
                for (Player p : Bukkit.getOnlinePlayers())
                {
                    setScoreboard(p);
                }
            }
        }, 0L, 1L);
    }
    It works fine on initial load. But when the server is reloaded the code does not run. Why? I'm guessing it's the config file.

    Also when Someone dies a error appears on the console!

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

    skipperguy12

  3. Offline

    creepers84

  4. Offline

    ZeusAllMighty11

    Only bump your thread every 12 hours!!!

    Nobody likes people who constantly bump their thread, when their question could've been fixed with some simple google searches.


    Your killer could be nul, you didn't even do a null check
     
  5. Offline

    creepers84

    Last time I checked random people couldn't read minds. It's amazing how you presume I haven't checked the wonderful resource of google. Although if you sustain this trait of constantly posting sarcastic and hurtful comments I'm sure your assumption will come true in your instance. "Nobody likes people who constantly bump their thread, when their question could've been fixed with some simple google searches."
    Why not try helping me? Like you haven't been doing on every thread I see you reply too!
     
  6. Offline

    ZeusAllMighty11

    lulwut I did help you
     
  7. Offline

    creepers84

    Which part of the previous post is meant to help me?
     
  8. Offline

    ZeusAllMighty11

    creepers84

     
  9. Offline

    creepers84

    Here is the code:
    Code:
    public File config;
    public FileConfiguration pConfig;
     
    @Override
    public void onEnable() {
        setupTimer();
        if(!(new File("plugins/ProjectileHeads/config.yml")).exists()){
            saveResource("config.yml", false);
    this.logger.info("[ProjectileHeads] Plugin Enabled");
    getServer().getPluginManager().registerEvents(this, this);
    getConfig().options().copyDefaults(true);
    saveDefaultConfig();
        }
    }
     
    @EventHandler
    public void PlayerJoinEvent(PlayerJoinEvent e){
        setScoreboard(e.getPlayer());
        config = new File("plugins/ProjectileHeads/config.yml");
        pConfig = YamlConfiguration.loadConfiguration(config);
        if(!config.exists()){
            pConfig.set(e.getPlayer().getName() + ".kills", "0");
            pConfig.set(e.getPlayer().getName() + ".deaths", "0");
            try {
                pConfig.save(config);
            } catch (IOException ex){ex.printStackTrace();}
        }
    }
     
    @EventHandler
    public void PlayerDeathEvent(PlayerDeathEvent e){
        Player p = e.getEntity().getPlayer();
     
        if (p.getKiller() instanceof Player){
            Player k = p.getKiller();
     
            setDeaths(p, getDeaths(p.getName()) + 1);
            setKills(k, getKills(k.getName()) + 1);
     
            setScoreboard(p);
            setScoreboard(k);
        } else {
            Player k = p.getKiller();
            getConfig().set(p.getName() + ".deaths", getDeaths(p.getName()) + 1);
            getConfig().set(k.getName() + ".kills", getKills(k.getName()) + 1);
            saveConfig();
     
            setScoreboard(p);
        }
    }
     
    public void setScoreboard(Player p){
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        Scoreboard board = manager.getNewScoreboard();
     
            Objective objective = board.registerNewObjective("test", "dummy");
     
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(" §b§lProjectileHeads");
     
            Score kills = objective.getScore(Bukkit.getOfflinePlayer("§aKills§7:§c"));
            kills.setScore(getKills(p.getName()));
     
            Score deaths = objective.getScore(Bukkit.getOfflinePlayer("§aDeaths§7:§c"));
            deaths.setScore(getDeaths(p.getName()));
     
            p.setScoreboard(board);
     
    }
     
    public int getKills(String p)
    {
        if(getConfig().get(p + ".kills") != null){
            return getConfig().getInt(p + ".kills");
        } else {
            return 0;
        }
    }
     
    public int getDeaths(String p)
    {
        return getConfig().getInt(p + ".deaths");
    }
     
    public double getKDR(Player p)
    {
        return getConfig().getDouble(p.getName() + ".kills") / getConfig().getDouble(p.getName() + ".deaths");
     
    }
    public void setKills(Player p, int Kills)
    {
        getConfig().set(p.getName() + ".kills", Kills);
        saveConfig();
    }
     
    public void setDeaths(Player p, int Deaths)
    {
        getConfig().set(p.getName() + ".deaths", Deaths);
        saveConfig();
    }
     
    public void setupTimer()
    {
        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
        {
            public void run() {
                for (Player p : Bukkit.getOnlinePlayers())
                {
                    setScoreboard(p);
                }
            }
        }, 0L, 1L);
    }
    See for yourself
     
  10. Offline

    ZeusAllMighty11

    Seriously, you need to help yourself because I'm not helping anymore if you can't even understand your own code or the slightest idea how to fix it. The internet is a database, use it.

    Code:
    if (p.getKiller() instanceof Player){
    
    Code:
    Your killer could be null, you didn't even do a null check
     
  11. Offline

    creepers84


    Ok thanks for the help. Oh and another thing I think you should use your "Database" to Google why the internet cannot be considered as a database. (Maybe doing your research would be more appropriate!) In your Words: "could've been fixed with some simple google searches."[/CODE][/quote][/CODE][/FONT][/SIZE][/COLOR][/quote]
    Ok thanks for the help. Oh and another think I think you should use your "Database" to Google why the internet cannot be considered as a database. (Maybe doing your research would be more appropriate!) In your Words: "could've been fixed with some simple google searches."[/CODE][/FONT][/SIZE][/COLOR][/quote]
     
  12. Offline

    ZeusAllMighty11

    You have 11 public plugins,you should be well capable of doing this.
     
  13. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Need to see the part of the error that actually relates to your plugin.
     
  14. Offline

    Ivan

    That's what I'm wondering too... O.0
     
  15. Offline

    creepers84

    So annoyed XD
     
  16. Offline

    Ivan

    How so?
     
  17. Offline

    Minecrell

    [Off topic] 5 of them are deleted or abandoned :p
     
    TheGreenGamerHD likes this.
  18. Offline

    savagesun

    I sort of just skimmed through the code, but I notice you are assigning information based on the player join event. This might be the cause of at least some of your errors. Try iterating through any online players in the onEnable event as well and do what you do in the join event? If it's not the cause of any console errors this would still cause a loss of information.
     
  19. Offline

    Ivan

    The issue has been resolved.
     
  20. Offline

    savagesun

    It didn't look solved from over here, sorry!
     
  21. Offline

    Ivan

    Dw about it. He created another duplicate thread (which has been locked due the fact that duplicates aren't allowed) and we helped him out over there.
     
  22. Offline

    creepers84

    Thanks =D
     
Thread Status:
Not open for further replies.

Share This Page