PLEASE HELP ive spent 3 days on this problem on my Minigame

Discussion in 'Plugin Development' started by DividedByZero, Aug 1, 2014.

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

    DividedByZero

    Code:
    package org.hiros.laserbattle.Hub;
     
    import java.util.HashMap;
    import java.util.UUID;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    import org.hiros.laserbattle.Config.HubConfig;
    import org.hiros.laserbattle.Messages.Messages;
     
    public class HubManager {
        private Plugin plugin;
        public HubManager(Plugin plugin) {
            this.plugin = plugin;
        }
       
        private static HubManager hm;
       
        private HubManager() {}
       
       
        //Data Vars
        public HashMap<UUID, String> hubplayers= new HashMap<UUID, String>();
        public HashMap<UUID, ItemStack[]> hubinv = new HashMap<UUID, ItemStack[]>();
        public HashMap<UUID, ItemStack[]> hubarmor = new HashMap<UUID, ItemStack[]>();
        public HashMap<UUID, Location> hubloc = new HashMap<UUID, Location>();
       
       
        public static HubManager getManager() {
            if(hm == null) {
                hm = new HubManager();
            }
            return hm;
        }
       
        public Hub getHub() {
            Hub h = new Hub(getHubSpawn());
            return h;
        }
       
       
        public void addPlayer(Player player) {
            UUID playerid = player.getUniqueId();   
            hubinv.put(playerid, player.getInventory().getContents());
            hubarmor.put(playerid, player.getInventory().getArmorContents());
            hubloc.put(playerid, player.getLocation());
           
            player.getInventory().clear();
            Location hubspawn = getHubSpawn();
            player.teleport(hubspawn);
           
            hubplayers.put(playerid, player.getName());
        }
       
        public Location getHubSpawn() {
            HubConfig hubconfig = new HubConfig(plugin);
            FileConfiguration s = hubconfig.getConfig();
           
            Location l = new Location(
                    Bukkit.getServer().getWorld(s.getString("hub.data.world")),
                    s.getDouble("hub.data.x"),
                    s.getDouble("hub.data.y"),
                    s.getDouble("hub.data.z"),
                    (float) s.getDouble("hub.data.pitch"),
                    (float) s.getDouble("hub.data.yaw")
                    );
            return l;
        }
       
       
        public void setHubSpawn(Player player) {
            Location l = player.getLocation();
            HubConfig hubconfig = new HubConfig(plugin);
            FileConfiguration s = hubconfig.getConfig();
           
            s.set("hub.data.x", l.getX());
            s.set("hub.data.y", l.getY());
            s.set("hub.data.z", l.getZ());
            s.set("hub.data.pitch", l.getPitch());
            s.set("hub.data.yaw", l.getYaw());
            s.set("hub.data.world", l.getWorld().getName());
           
            hubconfig.saveConfig();
        }
       
        public boolean isPlayerInHub(Player player) {
            UUID playerid = player.getUniqueId();
            return hubplayers.containsKey(playerid);
        }
       
        public void joinHub(Player player) {
            if(isPlayerInHub(player)) {
                player.sendMessage(Messages.prefix+ChatColor.DARK_RED+"You are already in the hub");
                return;
            }
            addPlayer(player);
            player.sendMessage(Messages.prefix+ChatColor.YELLOW+"You have joined the hub.");
        }
    }
    when I do
    if(isPlayerInHub(player)) {
    print("Is in hub");
    } else {
    print("Not in hub");
    }
    But the catch is when i do
    print(isPlayerInHub(player);
    its out put is correct. it returns true when the player uuid is in the hashmap and false when its not. IK java fairly well and idk wtf is happening here. PLEASE RESPOND
     
  2. Offline

    mythbusterma

    DividedByZero

    I seriously doubt you "know java fairly well" if you're not following simple conventions like naming and hiding implementation.

    That being said, you didn't even explain what the problem is.
     
  3. Offline

    DividedByZero

    I started coding with developing web based games with php. I usally do backed programing for server stuff. I have been learning java for about half a year now but im fairly new to the bukkit plat form. could you please help me with this problem. No one has been helpful to me so far?
     
  4. Offline

    mythbusterma

    DividedByZero

    That's because you didn't explain what went wrong. I have no idea what your problem is.
     
  5. Offline

    HiROs15

    mythbusterma this is my other account and my problem is when i call isPlayerInHub() by its self it returns the correct thing but if i put it in an If else block it always returns false
     
  6. Offline

    DividedByZero

    mythbusterma the problem is when i call
    Code:
    if(isPlayerInHub(player)) {
    print("Yes hes in hub")
    addPlayer(player);
    } else {
    print("You are already in the hub");
    }
    it would print "Yes hes in hub" every time i fire the block of code. IDK WTF IS HAPPENING
     
  7. Offline

    Necrodoom

Thread Status:
Not open for further replies.

Share This Page