-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkin.java
194 lines (172 loc) · 5.67 KB
/
Skin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.github.mafelp.minecraft.skins;
import com.github.mafelp.utils.Settings;
import org.bukkit.entity.Player;
import java.awt.image.BufferedImage;
import java.io.File;
/**
* Class with information about a Player's skin
*/
public class Skin {
/**
* The player whose skin is stored
*/
private final Player player;
/**
* The directory which contains the subdirectories skins/ and heads/
*/
private final File skinDirectory;
/**
* The format of the image (minecraft skins are always png)
*/
private static final String skinFormat = ".png";
/**
* The skin image
*/
private final BufferedImage skin;
/**
* The file which contains BufferedImage skin
*/
private final File skinFile;
/**
* The directory which contains all the skin files
*/
private final File skinDirectorySkins;
/**
* A sub image containing the head of a player
*/
private final BufferedImage head;
/**
* The file which contains the head
*/
private final File headFile;
/**
* The directory which contains all the head files
*/
private final File skinDirectoryHeads;
/**
* Main constructor
* @param player The Player whose skin to store in this class
* @param getSkinFromMojang If the skin should be downloaded from Mojang
*/
public Skin(Player player, boolean getSkinFromMojang) {
this.player = player;
this.skinDirectory = Settings.getConfigurationFileDirectory();
// If the skins should be gotten from Mojang or not
this.skinDirectorySkins = new File(skinDirectory, "skins/");
if (getSkinFromMojang) {
// If yes, ask the SkinManager to get the skin and save it
this.skin = SkinManager.getSkinFromMojang(player);
this.skinFile = SkinManager.saveImage(skin, skinDirectorySkins, player.getDisplayName());
} else {
// If not, get the skin from the files
this.skinFile = SkinManager.getSkinFile(player);
this.skin = SkinManager.getSkinFromFile(skinFile);
}
// If the skin is not null,
this.skinDirectoryHeads = new File(skinDirectory, "heads/");
if (skin != null) {
// And if the skins should be gotten from Mojang
if (getSkinFromMojang) {
// If yes, ask the SkinManager to get the head and save it.
this.head = SkinManager.getHead(skin);
this.headFile = SkinManager.saveImage(head, skinDirectoryHeads, player.getDisplayName());
} else {
// If not, get it from the files
this.headFile = SkinManager.getHeadFile(player);
this.head = SkinManager.getSkinFromFile(headFile);
}
} else {
// If the skin is null, also set the head to null
this.head = null;
this.headFile = null;
}
}
/**
* Creates a skin class and gets the skin and head from the stored files.
* @param player the player to store its skin in.
*/
public Skin(Player player){
this.player = player;
// Sets the directory for skins to the directory specified in the settings.
this.skinDirectory = Settings.getConfigurationFileDirectory();
// Sets the skin directory and ask the skin manager to get the skin from the skin file and save it.
this.skinDirectorySkins = new File(skinDirectory, "skins/");
this.skinFile = SkinManager.getSkinFile(player);
this.skin = SkinManager.getSkinFromFile(skinFile);
// Sets the head directory and check if the skin is not null
this.skinDirectoryHeads = new File(skinDirectory, "heads/");
if (skin != null) {
// Ask the skin manager to get the head (file)
this.headFile = SkinManager.getHeadFile(player);
this.head = SkinManager.getSkinFromFile(headFile);
} else {
// If the skin is null, also set the head to null
this.head = null;
this.headFile = null;
}
}
/**
* Getter for the Player whose skin is stored in this class
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* Getter for the directory which contains the child directories
* <code>skin/</code> and <code>head/</code>
* @return the parent directory as a file
*/
public File getSkinDirectory() {
return skinDirectory;
}
/**
* Returns the skinFormat
* @return ".png"
*/
public static String getSkinFormat() {
return skinFormat;
}
/**
* Getter for the image
* @return The skin as an image
*/
public BufferedImage getSkin() {
return skin;
}
/**
* Getter for the skin file
* @return file in which the skin is stored
*/
public File getSkinFile() {
return skinFile;
}
/**
* Getter for the directory with contains the skins
* @return File of the Directory in which are all the skin files
*/
public File getSkinDirectorySkins() {
return skinDirectorySkins;
}
/**
* Getter for the head image
* @return the head
*/
public BufferedImage getHead() {
return head;
}
/**
* Getter for the file which contains the head.
* @return The file which contains the head
*/
public File getHeadFile() {
return headFile;
}
/**
* Getter for the directory in which all the heads are stored
* @return the directory in which the heads are stored
*/
public File getSkinDirectoryHeads() {
return skinDirectoryHeads;
}
}