Solved Am I CRAZY! Files are not there but they are storing data.

Discussion in 'Plugin Development' started by DividedByZero, Jan 2, 2015.

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

    DividedByZero

    Alright I was coding this half asleep and now things are getting strange. I am storing player data in files like "Playername.yml" in the members folder. I store stuff like the player credits and the player coins. Now the files are not being created. Like they dont show up on my server or computer but the coins data is correct. WHAT IS HAPPENING!

    Look at the economymanager class and the HubManager class. joinHub() is called when the player logs in.

    EconomyManager.class
    [
    Code:
    package dev.hiros.Economy;
    
    import org.bukkit.entity.Player;
    import dev.hiros.Config.Config;
    
    public class EconomyManager {
        private static EconomyManager inst = new EconomyManager();
        public static EconomyManager getInstance() {
            return inst;
        }
     
        public void setupEconomyForPlayer(Player player) {
            String path = "/members/"+player.getName()+".yml";
            if(Config.getInstance().getConfig(path).getBoolean("economy.setup") != true) {
                Config.getInstance().getConfig(path).set("economy.setup", true);
                Config.getInstance().getConfig(path).set("economy.credits", 500);
                Config.getInstance().getConfig(path).set("economy.coins", 5);
                Config.getInstance().saveConfig(path);
            }
        }
     
        public int getCoins(Player player) {
            return Config.getInstance().getConfig("/members/"+player.getName()+".yml").getInt("economy.coins");
        }
     
        public int getCredits(Player player) {
            return Config.getInstance().getConfig("/members/"+player.getName()+".yml").getInt("economy.credits");
        }
     
        public void setCredits(Player player, int value) {
            String path = "/members/"+player.getName()+".yml";
            Config.getInstance().getConfig(path).set("economy.credits", value);
            Config.getInstance().saveConfig(path);
        }
     
        public void setCoins(Player player, int value) {
            String path = "/members/"+player.getName()+".yml";
            Config.getInstance().getConfig(path).set("economy.coins", value);
            Config.getInstance().saveConfig(path);
        }
    }
    HubManager.class
    Code:
    package dev.hiros.Hub;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    
    import dev.hiros.SakuraNetwork;
    import dev.hiros.Bungee.Bungee;
    import dev.hiros.Economy.EconomyManager;
    
    public class HubManager {
        private static HubManager inst = new HubManager();
        public static HubManager getInstance() {
            return inst;
        }
     
        ArrayList<HubPlayer> hubPlayers = new ArrayList<HubPlayer>();
     
        @SuppressWarnings("deprecation")
        public void joinHub(Player player) {
            if(getPlayer(player) != null) {
                player.sendMessage(ChatColor.GREEN+"SYSTEM> "+ChatColor.GRAY+"You are already in the hub.");
                return;
            }
         
            if(SakuraNetwork.getInstance().getConfig().getBoolean("sakuranetwork.hub.setup") != true) {
                player.sendMessage(ChatColor.GREEN+"SYSTEM> "+ChatColor.GRAY+"The hub is currently not setup.");
                return;
            }
         
            //Start the join hub stuff
            hubPlayers.add(new HubPlayer(player));
            teleportPlayerToHub(player);
            setupHubBossBar(player);
            setupHubInventory(player);
         
            //Change player mode to adventure
            if(player.hasPermission("sakuranetwork.sakuramember") || player.hasPermission("sakuranetwork.admin") || player.hasPermission("sakuranetwork.mod")) {
                player.setGameMode(GameMode.CREATIVE);
            } else {
                player.setGameMode(GameMode.ADVENTURE);
            }
         
            //Setup the economy for the player joining the hub
            EconomyManager.getInstance().setupEconomyForPlayer(player);
         
            //Setup the hub scoreboard
            HubScoreboard.getInstance().showHubScoreboard(player);
         
            //Set the hub texture pack
            player.setResourcePack("http://sakurapack.x10.mx/HubPack1.zip");
         
            //Start the particle effects
            HubParticles.getInstance().startRunningParticle(player);
         
            //Check if they are a sakura member and play the sound
            if(player.hasPermission("sakuranetwork.sakuramember")) {
                for(HubPlayer p : hubPlayers) {
                    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "playsound hub.sakuramember_join "+p.getPlayer().getName()+" "+p.getPlayer().getLocation().getX()+" "+p.getPlayer().getLocation().getY()+" "+p.getPlayer().getLocation().getZ()+" 100 1 1");
                    p.getPlayer().sendMessage(ChatColor.RED+""+ChatColor.BOLD+"ATTENTION "+ChatColor.RESET+""+ChatColor.BLUE+""+player.getName()+" has just entered the hub!");
                }
            }
         
            //Bungee the players
            for(Player p : Bukkit.getOnlinePlayers()) {
                if(getPlayer(p) == null) {
                    Bungee.getInstance().hidePlayers(player, p);
                }
                else if(getPlayer(p) != null) {
                    Bungee.getInstance().showPlayers(player, p);
                }
            }
        }
     
        public void teleportPlayerToHub(Player player) {
            Plugin plugin = SakuraNetwork.getInstance();
         
            if(plugin.getConfig().getBoolean("sakuranetwork.hub.setup") != true) {
                player.sendMessage(ChatColor.GREEN+"SYSTEM> "+ChatColor.GRAY+"Server cannot teleport player to hub because it is not setup.");
                return;
            }
         
            Location loc = new Location(
                    Bukkit.getServer().getWorld(plugin.getConfig().getString("sakuranetwork.hub.world")),
                    plugin.getConfig().getDouble("sakuranetwork.hub.x"),
                    plugin.getConfig().getDouble("sakuranetwork.hub.y"),
                    plugin.getConfig().getDouble("sakuranetwork.hub.z"),
                    (float) plugin.getConfig().getDouble("sakuranetwork.hub.yaw"),
                    (float) plugin.getConfig().getDouble("sakuranetwork.hub.pitch")
                    );
            player.teleport(loc);
        }
     
        public HubPlayer getPlayer(Player player) {
            for(HubPlayer hubplayer : hubPlayers) {
                if(hubplayer.getPlayer().equals(player)) {
                    return hubplayer;
                }
            }
            return null;
        }
     
        public void setupHubInventory(Player player) {
            player.getInventory().clear();
         
            player.getInventory().setItem(0, createItem(Material.SLIME_BALL, ChatColor.AQUA+"Quick Warp"));
            player.getInventory().setItem(4, createItem(Material.EMERALD, ChatColor.GOLD+"Sakura Shop"));
            player.getInventory().setItem(8, createItem(Material.REDSTONE_BLOCK, ChatColor.BLUE+"Settings"));
            String coinname = ChatColor.LIGHT_PURPLE+""+ChatColor.BOLD+"Coin"+ChatColor.RESET+""+ChatColor.GRAY+" (Press Q to drop)";
            player.getInventory().setItem(2, createItem(Material.COAL, coinname));
            player.getInventory().setItem(7, createItem(Material.NETHER_STAR, ChatColor.RED+""+ChatColor.BOLD+"My Stuff "+ChatColor.RESET+""+ChatColor.GRAY+"(Right Clcik)"));
        }
     
        public void setupHubBossBar(Player player) {
            me.mgone.bossbarapi.BossbarAPI.setMessage(player, ChatColor.AQUA+"★ "+ChatColor.LIGHT_PURPLE+""+ChatColor.BOLD+"SAKURA NETWORK"+ChatColor.RESET+" "+ChatColor.AQUA+"★");
        }
     
        public ItemStack createItem(Material m, String name) {
            ItemStack item = new ItemStack(m);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(name);
            item.setItemMeta(meta);
            return item;
        }
     
        public void dropSakuraCoin(Player player) {
            if(EconomyManager.getInstance().getCoins(player) > 0) {
                //spawn the item
                Location coinLoc = player.getLocation().add(0, 1, 0);
                int rand = (int)(Math.random()*99999999);
             
                Item coin = player.getLocation().getWorld().dropItem(coinLoc, new ItemStack(Material.COAL));
                ItemMeta meta = coin.getItemStack().getItemMeta();
                meta.setDisplayName("Coin"+rand);
                coin.getItemStack().setItemMeta(meta);
                coin.setVelocity(coinLoc.getDirection().multiply(0.8));
             
                EconomyManager.getInstance().setCoins(player, EconomyManager.getInstance().getCoins(player)-1);
             
                //update the hub scoreboard
                HubScoreboard.getInstance().removeHubScoreboard(player);
                HubScoreboard.getInstance().showHubScoreboard(player);
             
                //Play the cash sound to all hub players
                for(HubPlayer p : hubPlayers) {
                    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "playsound hub.cash "+p.getPlayer().getName()+" "+player.getLocation().getX()+" "+player.getLocation().getY()+" "+player.getLocation().getZ()+" 1.2");
                }
            }
        }
     
        public void pickupSakuraCoin(final Player player, Item item, int ammount) {
            EconomyManager.getInstance().setCoins(player, EconomyManager.getInstance().getCoins(player)+ammount);
         
            //Update the hub scoreboard
            HubScoreboard.getInstance().removeHubScoreboard(player);
            HubScoreboard.getInstance().showHubScoreboard(player);
         
            //reset the player inventory
         
            //play the cash sound
            for(HubPlayer p : hubPlayers) {
                Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "playsound hub.cash "+p.getPlayer().getName()+" "+player.getLocation().getX()+" "+player.getLocation().getY()+" "+player.getLocation().getZ()+" 1.2");
            }
         
            SakuraNetwork.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(SakuraNetwork.getInstance(), new Runnable() {
                public void run() {
                    player.getInventory().clear();
                    setupHubInventory(player);
                }
            }, 1L);
        }
     
        @SuppressWarnings("deprecation")
        public void leaveHub(Player player) {
            //remove from hubplayers array
            hubPlayers.remove(getPlayer(player));
         
            player.getInventory().clear();
         
            HubScoreboard.getInstance().removeHubScoreboard(player);
         
            SakuraNetwork.getInstance().getLogger().info(player.getName()+" has been removed from the hub.");
         
            //Bungee the players
            for(Player p : Bukkit.getOnlinePlayers()) {
                if(getPlayer(p) != null) {
                    Bungee.getInstance().hidePlayers(p, player);
                } else if(getPlayer(p) == null) {
                    Bungee.getInstance().showPlayers(player, p);
                }
            }
        }
    }
    Actually i think ik where the problem lies. In my Config.class file i use static data to get the instance.

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

    MCMatters

    @DividedByZero

    Haven't looked at ur classes but I think the problem is you aren't calling saveConfig()
     
  3. Offline

    werter318

    @MCMatters Well maybe you should then because he is saving the configs.
     
  4. Offline

    DividedByZero

    i figured it out. It was becuase i was ussing Config.getInstance.saveConfig(path); which created a new instance of the class config. meaning theyre was nothing to save but it kept it in the ram
     
  5. Offline

    CheesyFreezy

    @DividedByZero , please change the title prefix to 'Solved'

    <Edited by bwfcwalshy: Done.>
     
    Last edited by a moderator: Jan 4, 2015
Thread Status:
Not open for further replies.

Share This Page