Started using TBMCPlayer and added save();
This commit is contained in:
parent
5f62df97de
commit
5a559aa4c3
2 changed files with 24 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
package buttondevteam.lib.player;
|
package buttondevteam.lib.player;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
@ -68,8 +69,26 @@ public abstract class ChromaGamerBase implements AutoCloseable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the player. It'll pass all exceptions to the caller. To automatically handle the exception, use {@link #save()} instead.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void close() throws Exception {
|
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"));
|
plugindata.save(new File(TBMC_PLAYERS_DIR + getFolder(), getFileName() + ".yml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,13 +114,9 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
|
||||||
/**
|
/**
|
||||||
* Only intended to use from ButtonCore
|
* Only intended to use from ButtonCore
|
||||||
*/
|
*/
|
||||||
public static void joinPlayer(UUID uuid) {
|
public static void joinPlayer(Player p) {
|
||||||
YamlConfiguration yc;
|
TBMCPlayer player = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class);
|
||||||
if (playerfiles.containsKey(uuid))
|
Bukkit.getLogger().info("Loaded player: " + player.getPlayerName());
|
||||||
yc = playerfiles.get(uuid);
|
|
||||||
else
|
|
||||||
playerfiles.put(uuid, yc = YamlConfiguration.loadConfiguration(new File("minecraft", uuid + ".yml")));
|
|
||||||
/*Bukkit.getLogger().info("Loaded player: " + player.getPlayerName());
|
|
||||||
if (player.getPlayerName() == null) {
|
if (player.getPlayerName() == null) {
|
||||||
player.setPlayerName(p.getName());
|
player.setPlayerName(p.getName());
|
||||||
Bukkit.getLogger().info("Player name saved: " + player.getPlayerName());
|
Bukkit.getLogger().info("Player name saved: " + player.getPlayerName());
|
||||||
|
@ -146,7 +142,8 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
|
||||||
|
|
||||||
// Load in other plugins
|
// Load in other plugins
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerLoadEvent(player));
|
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerLoadEvent(player));
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerJoinEvent(player));*/
|
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerJoinEvent(player));
|
||||||
|
player.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue