SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class CustomSkinManager {
  3.  
  4.     public static final String DB_NAME = Kyrgon.MODID + ":customskins";
  5.  
  6.     private static CustomSkinManager instance;
  7.  
  8.     public static CustomSkinManager getInstance() {
  9.         if(instance == null) instance = new CustomSkinManager();
  10.         return instance;
  11.     }
  12.  
  13.     private Database getDB(){
  14.         return Databases.getDatabase(DB_NAME);
  15.     }
  16.  
  17.    public boolean hasSkin(EntityPlayer player)
  18.    {
  19.        return hasSkin(player.getName());
  20.    }
  21.  
  22.    public boolean hasSkin(String playerName)
  23.    {
  24.        Skin skin = Skin.fromString(getDB().getString(playerName));
  25.        return (!skin.isDefault());
  26.    }
  27.  
  28.    public Skin getSkin(EntityPlayer player)
  29.    {
  30.        return getSkin(player.getName());
  31.    }
  32.  
  33.    public Skin getSkin(String playerName)
  34.    {
  35.         return hasSkin(playerName) ? Skin.fromString(getDB().getString(playerName)) : Skin.DEFAULT_SKIN;
  36.    }
  37.    
  38.    public void setSkin(EntityPlayer player, Skin skin)
  39.    {
  40.        setSkin(player.getName(), skin);
  41.    }
  42.    
  43.    public void setSkin(String playerName, Skin skin)
  44.    {
  45.        getDB().setString(playerName, skin.toString());
  46.    }
  47.  
  48.    public static class Skin
  49.    {
  50.        private String name;
  51.        private String link;
  52.  
  53.        public Skin(String name, String link)
  54.        {
  55.            this.name = name;
  56.            this.link = link;
  57.        }
  58.  
  59.        public String getName()
  60.        {
  61.            return name;
  62.        }
  63.  
  64.        public void setName(String name)
  65.        {
  66.            this.name = name;
  67.        }
  68.  
  69.        public String getLink()
  70.        {
  71.            return link;
  72.        }
  73.  
  74.        public void setLink(String link)
  75.        {
  76.            this.link = link;
  77.        }
  78.  
  79.        @Override
  80.        public String toString()
  81.        {
  82.            return name + ":" + link;
  83.        }
  84.  
  85.        public boolean isDefault()
  86.        {
  87.            return !(name.equalsIgnoreCase("") || name.equalsIgnoreCase("default")) && !(link.equalsIgnoreCase("") || link.equalsIgnoreCase("default"));
  88.        }
  89.  
  90.        public static Skin DEFAULT_SKIN = new Skin("default", "default");
  91.  
  92.        public static Skin fromString(String string)
  93.        {
  94.            String[] parts = string.split(":");
  95.            if(parts.length == 2)
  96.            {
  97.                return new Skin(parts[0], parts[1]);
  98.            }
  99.            return DEFAULT_SKIN;
  100.        }
  101.    }
  102.  
  103. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top