Skip to content

Commit 600d177

Browse files
author
TheProgramSrc
committed
Change Log:
+ Added SkinTexture Head DataBase + Added SuperCoreAPI Update Checker • Improvements • Bug Fixes
1 parent 8f808e6 commit 600d177

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>xyz.theprogramsrc</groupId>
88
<artifactId>SuperCoreAPI</artifactId>
9-
<version>3.6.2</version>
9+
<version>3.6.3</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>

src/main/java/xyz/theprogramsrc/supercoreapi/global/data/PluginDataStorage.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public class PluginDataStorage extends JsonConfig {
1616

1717
public PluginDataStorage(SuperPlugin<?> plugin){
1818
super(plugin.getPluginFolder(), "PluginData.json");
19-
if(!this.contains("stats_id")){
20-
this.add("stats_id", UUID.randomUUID().toString());
21-
}
19+
this.add("stats_id", UUID.randomUUID().toString());
2220
}
2321

2422
public void saveNotification(Notification notification){

src/main/java/xyz/theprogramsrc/supercoreapi/global/files/JsonConfig.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ public JsonConfig(File file){
2424
JsonObject json;
2525
if(file.exists()){
2626
try{
27-
json = new JsonParser().parse(Utils.readFile(file)).getAsJsonObject();
27+
String content = Utils.readFile(file);
28+
if(content == null){
29+
json = new JsonObject();
30+
}else{
31+
if(content.isEmpty() || content.equals(" ")){
32+
json = new JsonObject();
33+
}else{
34+
json = new JsonParser().parse(Utils.readFile(file)).getAsJsonObject();
35+
}
36+
}
2837
}catch (Exception ex){
2938
ex.printStackTrace();
3039
json = new JsonObject();
@@ -126,6 +135,7 @@ public void add(String key, JsonElement value){
126135
*/
127136
public void set(String key, String value){
128137
this.json.addProperty(key, value);
138+
this.save();
129139
}
130140

131141
/**

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/SpigotPlugin.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import xyz.theprogramsrc.supercoreapi.global.dependencies.classloader.ReflectionClassLoader;
1313
import xyz.theprogramsrc.supercoreapi.global.translations.Base;
1414
import xyz.theprogramsrc.supercoreapi.global.translations.TranslationManager;
15+
import xyz.theprogramsrc.supercoreapi.global.updater.SpigotUpdateChecker;
1516
import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
1617
import xyz.theprogramsrc.supercoreapi.spigot.events.EventManager;
1718
import xyz.theprogramsrc.supercoreapi.spigot.items.PreloadedItems;
@@ -258,4 +259,17 @@ public EventManager getEventManager() {
258259
public PluginDataStorage getPluginDataStorage() {
259260
return this.pluginDataStorage;
260261
}
262+
263+
public void checkCoreUpdates(){
264+
new SpigotUpdateChecker("77096"){
265+
@Override
266+
public void onCheckFail() { }
267+
268+
@Override
269+
public void onCheckSuccess(String lastVersion) {
270+
SpigotPlugin.this.log("&c&lThis is not an error, this is a warning for the plugin developer that the SuperCoreAPI is outdated");
271+
SpigotPlugin.this.log("Please update SuperCoreAPI to v" + lastVersion);
272+
}
273+
}.check();
274+
}
261275
}

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/skintexture/SkinTextureManager.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33

44
import org.bukkit.Bukkit;
55
import org.bukkit.entity.Player;
6+
import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
67

8+
import java.util.Arrays;
79
import java.util.HashMap;
810

911
public class SkinTextureManager {
1012

1113
private final HashMap<String, SkinTexture> cache;
14+
private final HashMap<String, SkinTexture> urls;
1215

1316
public SkinTextureManager(){
1417
this.cache = new HashMap<>();
18+
this.urls = new HashMap<>();
1519
}
1620

1721
/**
@@ -30,10 +34,38 @@ public SkinTexture getSkin(Player player) {
3034
return this.cache.get(player.getName());
3135
}
3236

37+
public SkinTexture getSkin(String url){
38+
if(!this.urls.containsKey(url)){
39+
SkinTexture texture = SkinTexture.fromURL(url);
40+
this.urls.put(url, texture);
41+
}
42+
43+
return this.urls.get(url);
44+
}
45+
3346
/**
3447
* Clears the skin cache
3548
*/
3649
public void clearCache(){
3750
this.cache.clear();
51+
this.urls.clear();
52+
}
53+
54+
/**
55+
* Gets a SkinTexture from the database
56+
* @param name the name
57+
* @return null if there is any error, otherwise the skin
58+
*/
59+
public SkinTexture fromDataBase(String name){
60+
try{
61+
String content = Utils.readWithInputStream("https://raw.githubusercontent.com/TheProgramSrc/PluginsResources/master/SuperCoreAPI/Heads");
62+
if(content == null) return null;
63+
String textureURL = Arrays.stream(content.split(";")).filter(s-> s.split(":")[0].equalsIgnoreCase(name)).findFirst().orElse(null);
64+
if(textureURL == null) return null;
65+
return this.getSkin(textureURL.split(":")[1]);
66+
}catch (Exception ex){
67+
ex.printStackTrace();
68+
return null;
69+
}
3870
}
3971
}

0 commit comments

Comments
 (0)