Remade user data managing, added a test #30

Merged
NorbiPeti merged 22 commits from dev into master 2017-04-15 11:54:06 +00:00
2 changed files with 24 additions and 8 deletions
Showing only changes of commit 5a559aa4c3 - Show all commits

View file

@ -1,6 +1,7 @@
package buttondevteam.lib.player;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.function.Consumer;
@ -68,8 +69,26 @@ public abstract class ChromaGamerBase implements AutoCloseable {
return null;
}
/**
* Saves the player. It'll pass all exceptions to the caller. To automatically handle the exception, use {@link #save()} instead.
*/
@Override
public void close() throws Exception {
save_();
}
/**
* Saves the player. It'll send all exceptions that may happen. To catch the exception, use {@link #close()} instead.
*/
public void save() {
try {
save_();
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while saving player data!", e);
}
}
private void save_() throws IOException {
plugindata.save(new File(TBMC_PLAYERS_DIR + getFolder(), getFileName() + ".yml"));
}

View file

@ -114,13 +114,9 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
/**
* Only intended to use from ButtonCore
*/
public static void joinPlayer(UUID uuid) {
YamlConfiguration yc;
if (playerfiles.containsKey(uuid))
yc = playerfiles.get(uuid);
else
playerfiles.put(uuid, yc = YamlConfiguration.loadConfiguration(new File("minecraft", uuid + ".yml")));
/*Bukkit.getLogger().info("Loaded player: " + player.getPlayerName());
public static void joinPlayer(Player p) {
TBMCPlayer player = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class);
Bukkit.getLogger().info("Loaded player: " + player.getPlayerName());
if (player.getPlayerName() == null) {
player.setPlayerName(p.getName());
Bukkit.getLogger().info("Player name saved: " + player.getPlayerName());
@ -146,7 +142,8 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
// Load in other plugins
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerLoadEvent(player));
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerJoinEvent(player));*/
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerJoinEvent(player));
player.save();
}
/**