-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two config files, finally!
- Loading branch information
Xenoyia
committed
May 9, 2017
1 parent
7b5459c
commit 1f45488
Showing
7 changed files
with
128 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.xpgaming.xPPokeDex; | ||
|
||
import com.google.common.reflect.TypeToken; | ||
import com.google.inject.Inject; | ||
import ninja.leaping.configurate.commented.CommentedConfigurationNode; | ||
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; | ||
import ninja.leaping.configurate.loader.ConfigurationLoader; | ||
import ninja.leaping.configurate.objectmapping.ObjectMappingException; | ||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.config.ConfigDir; | ||
import org.spongepowered.api.config.DefaultConfig; | ||
import org.spongepowered.api.item.ItemType; | ||
import org.spongepowered.api.item.inventory.ItemStack; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
public class UserData { | ||
private static UserData instance = new UserData(); | ||
|
||
public static UserData getInstance() { | ||
return instance; | ||
} | ||
|
||
private CommentedConfigurationNode data; | ||
@Inject @ConfigDir(sharedRoot = false) private File configDir; | ||
String path = "config"+File.separator+"xPPokeDex"; | ||
private File dataFile = new File(path, "data.conf"); | ||
private ConfigurationLoader<CommentedConfigurationNode> dataLoader = HoconConfigurationLoader.builder().setFile(dataFile).build(); | ||
|
||
public void dataCreate() throws ObjectMappingException { | ||
try { | ||
if(!dataFile.getParentFile().exists()) dataFile.getParentFile().mkdirs(); | ||
dataFile.createNewFile(); | ||
dataLoad(); | ||
CommentedConfigurationNode pd = data.getNode("playerData").setComment("Do not mess with this unless you know what you are doing!"); | ||
dataSave(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void setup(File dataFile, ConfigurationLoader<CommentedConfigurationNode> dataLoader) { | ||
this.dataLoader = dataLoader; | ||
this.dataFile = dataFile; | ||
if (!dataFile.exists()) { | ||
try { | ||
dataCreate(); | ||
} catch (ObjectMappingException e) { | ||
e.printStackTrace(); | ||
} | ||
} else | ||
dataLoad(); | ||
} | ||
|
||
public CommentedConfigurationNode getConfig() { | ||
return data; | ||
} | ||
|
||
public void dataLoad() { | ||
if (!dataFile.exists()) { | ||
try { | ||
dataCreate(); | ||
} catch (ObjectMappingException e) { | ||
e.printStackTrace(); | ||
} | ||
} else | ||
try { | ||
data = dataLoader.load(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void dataSave() { | ||
try { | ||
dataLoader.save(data); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void saveAndLoadConfig() { | ||
dataSave(); | ||
dataLoad(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters